Hi I'm learning linear algebra with python with an Edx course. (http://nbviewer.ipython.org/github/ULAFF/notebooks/tree/may-14-2014/).
嗨,我正在学习线性代数与python与Edx课程。 (http://nbviewer.ipython.org/github/ULAFF/notebooks/tree/may-14-2014/)。
On "02.4.2.10 Practice with matrix-vector multiplication" with the first box, the code is:
在“02.4.2.10用矩阵向量乘法练习”的第一个框中,代码为:
import generate_problems as gp
print("What is the result of the matrix vector product below?")
p = gp.Problem()
p.new_problem()
generate_problems is a module that the professor at Edx created. However, I got an error importing sympy.
While I was trying to execute the code above, I got the error below:
当我尝试执行上面的代码时,我收到以下错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-79d56e0988cb> in <module>()
2 print("What is the result of the matrix vector product below?")
3
----> 4 p = gp.Problem()
5
6 p.new_problem()
/Users/user/Desktop/Course/Python/ipython/notebooks-master/generate_problems.pyc in __init__(self)
14 tag = ''
15
---> 16 A = self.random_integer_matrix( m, n )
17 x = self.random_integer_matrix( n, 1 )
18
/Users/user/Desktop/Course/Python/ipython/notebooks-master/generate_problems.pyc in random_integer_matrix(self, m, n)
26
27 def random_integer_matrix( self, m, n ):
---> 28 A = zeros( (m, n) )
29
30 for i in range( m ):
/Users/user/anaconda/lib/python2.7/site-packages/sympy/matrices/dense.pyc in zeros(r, c, cls)
1227 if cls is None:
1228 from .dense import Matrix as cls
-> 1229 return cls.zeros(r, c)
1230
1231
/Users/user/anaconda/lib/python2.7/site-packages/sympy/matrices/dense.pyc in zeros(cls, r, c)
511 """Return an r x c matrix of zeros, square if c is omitted."""
512 c = r if c is None else c
--> 513 r = as_int(r)
514 c = as_int(c)
515 return cls._new(r, c, [cls._sympify(0)]*r*c)
/Users/user/anaconda/lib/python2.7/site-packages/sympy/core/compatibility.pyc in as_int(n)
387 raise TypeError
388 except TypeError:
--> 389 raise ValueError('%s is not an integer' % n)
390 return result
391
TypeError: not all arguments converted during string formatting
I seems like too few %s for compatibility.py? I use Anaconda on Mac OSX Yosemite. Could someone help?
对于compatibility.py,我似乎太少了%s?我在Mac OSX Yosemite上使用Anaconda。有人可以帮忙吗?
1 个解决方案
#1
0
It looks like the course code does not support the latest version of SymPy, which has made an API change (zeros()
now works like zeros(r, c)
instead of zeros((r, c))
as it is in generate_problems.py
). You may be able to fix it by editing the code in /Users/user/Desktop/Course/Python/ipython/notebooks-master/generate_problems.py
.
看起来课程代码不支持最新版本的SymPy,它已经进行了API更改(零()现在的工作方式类似于零(r,c)而不是零((r,c)),因为它在generate_problems中。 PY)。您可以通过编辑/Users/user/Desktop/Course/Python/ipython/notebooks-master/generate_problems.py中的代码来修复它。
#1
0
It looks like the course code does not support the latest version of SymPy, which has made an API change (zeros()
now works like zeros(r, c)
instead of zeros((r, c))
as it is in generate_problems.py
). You may be able to fix it by editing the code in /Users/user/Desktop/Course/Python/ipython/notebooks-master/generate_problems.py
.
看起来课程代码不支持最新版本的SymPy,它已经进行了API更改(零()现在的工作方式类似于零(r,c)而不是零((r,c)),因为它在generate_problems中。 PY)。您可以通过编辑/Users/user/Desktop/Course/Python/ipython/notebooks-master/generate_problems.py中的代码来修复它。