我对 Python 很陌生。我需要一个 3 维矩阵,以便以一定长度保存 8 x 8 矩阵。让我们拨打 530。问题是我使用了 np.array,因为 numpy 认为矩阵不能超过 2 维。
R = zeros([8,8,530],float)
我将我的 8 x 8 矩阵计算为 np.matrix
R[:,:,ii] = smallR
然后我尝试将其保存在 mat 文件中,因为 scipy 声称这样做。
sio.savemat('R.mat',R)
但是,错误说“numpy.ndarray”对象没有属性“项目”
/usr/local/lib/python2.7/dist-packages/scipy/io/matlab/mio.py:266: FutureWarning: Using oned_as default value ('column') This will change to 'row' in future versions
oned_as=oned_as)
Traceback (most recent call last):
File "ClassName.py", line 83, in <module>
print (buildR()[1])
File "ClassName.py", line 81, in buildR
sio.savemat('R.mat',R)
File "/usr/local/lib/python2.7/dist-packages/scipy/io/matlab/mio.py", line 269, in savemat
MW.put_variables(mdict)
File "/usr/local/lib/python2.7/dist-packages/scipy/io/matlab/mio5.py", line 827, in put_variables
for name, var in mdict.items():
AttributeError: 'numpy.ndarray' object has no attribute 'items'