这是从这个线程继续说道:Python matrix, any solution?Python的矩阵问题
输入
from numpy import *
import numpy
x=[['1','7'],
['1.5', '8'],
['2', '5.5'],
['2','9']]
代码
y = x[:, :, None] * x[:, None]
print y.sum(axis=0)
我收到的错误:
"list indices must be integers, not tuple"
但如果x是 x = numpy.array([[1, 7], [1.5, 8], [2, 5.5], [2, 9]])
那么它的好,但我没有这样输入。
解释比numpy的阵列不同。如果你想使用numpy操作,你需要首先将你的列表转换为数组。 – recursive 2011-04-29 20:06:36
我该怎么做?我尝试了很多东西,但在输入中没有成功 – thaking 2011-04-29 20:07:47
,您在每行之后都省略了逗号。 – kefeizhou 2011-04-29 20:10:52