arr2=[0]*(x^2) # x is the length of the list data
for i in range(x):
arr2[i]=data[i].split(',')#data is a list like:['1,2','3,4']
arr2=np.array(arr2)
A=np.asmatrix(arr2)
print A.I
设置带序列
的数组元素时出错答案 0 :(得分:0)
这样的事情:
>>> data = ['1,2','3,4']
>>> arr2=[ map(float,x.split(',')) for x in data]
>>> arr2 = np.asarray(arr2)
>>> A = np.asmatrix(arr2)
>>> A.I
matrix([[-2. , 1. ],
[ 1.5, -0.5]])