“类型错误:不是所有在字符串格式化过程中转换的参数”在ipython笔记本

问题描述:

您好我正在学习Python与Edx课程的线性代数。 (http://nbviewer.ipython.org/github/ULAFF/notebooks/tree/may-14-2014/)。“类型错误:不是所有在字符串格式化过程中转换的参数”在ipython笔记本

在“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. 

当我试图执行上面的代码中,我得到了以下错误:

--------------------------------------------------------------------------- 
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 

我好像太少%s为compatibility.py?我在Mac OSX Yosemite上使用Anaconda。有人可以帮忙吗?

+0

任何人都可以帮忙吗? – pythonlearner

它看起来像课程代码不支持最新版本的SymPy的,这使得一个API的变化(zeros()现在就像zeros(r, c),而不是zeros((r, c)),因为它是在generate_problems.py)。您可以通过编辑/Users/user/Desktop/Course/Python/ipython/notebooks-master/generate_problems.py中的代码来修复它。