数据类型不明白

我试着用一个矩阵来计算,代码是这样的

import numpy as np
# some code
mmatrix = np.zeros(nrows, ncols)
print mmatrix[0, 0]

但我得到’数据类型不明白’,它的工作,如果我这样做,从终端。

181387 次浏览

Try:

mmatrix = np.zeros((nrows, ncols))

Since the shape parameter has to be an int or sequence of ints

http://docs.scipy.org/doc/numpy/reference/generated/numpy.zeros.html

Otherwise you are passing ncols to np.zeros as the dtype.