Python 保存数组至.mat文件,报错:AttributeError: 'numpy.ndarray' object has no attribute 'items'
2017-09-15 14:42
3807 查看
Python保存数组的方式有很多种,如savetxt,但这个函数只能保存一维或二维数组。为了保存高维数组,同时能够在matlab载入,可以使用scipy.io.savemat()函数,例子:
得到输出:
在matlab中导入该数组:
可以看到,matlab与Python对矩阵的保存上有一定的变换,从Python到matlab为:’页’->’行’,’行’->’列’,’列’->’页’,即在Python中的矩阵形状为3×4×5,在matlab中变为5×3×4。
另外,在Python中如果保存成.mat文件时代码为:
import numpy as np import scipy.io as sio A = np.array([[[1, 2], [3, 4]],[[5, 6], [7, 8]]]) print A print A.shape sio.savemat('data.mat', {"foo":A})
得到输出:
在matlab中导入该数组:
>>load('data.mat')
可以看到,matlab与Python对矩阵的保存上有一定的变换,从Python到matlab为:’页’->’行’,’行’->’列’,’列’->’页’,即在Python中的矩阵形状为3×4×5,在matlab中变为5×3×4。
另外,在Python中如果保存成.mat文件时代码为:
sio.savemat('data.mat', A),则会报错
AttributeError: 'numpy.ndarray' object has no attribute 'items'
相关文章推荐
- Python3下AttributeError: 'dict' object has no attribute 'iteritems'的问题分析
- Python3下错误AttributeError: ‘dict’ object has no attribute’iteritems‘的分析与解决
- 解决python中问题AttributeError: 'collections.defaultdict' object has no attribute 'iteritems'
- Python2.X与Python3.X编程代码笔记(1):AttributeError: 'dict' object has no attribute 'iteritems'
- AttributeError: 'numpy.ndarray' object has no attribute 'value_counts'
- Python3下AttributeError: 'dict' object has no attribute 'iteritems'的问题分析
- AttributeError: 'module' object has no attribute 'AF_INET'处理办法——python
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- 'numpy.ndarray' object has no attribute 'values'
- python 提示错误AttributeError: type object 'str' has no attribute '_name_'
- 【python】AttributeError: 'module' object has no attribute 'HTTPSConnection'
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python报错——错误“AttributeError:'builtin_function_or_method' object has no attribute 'sleep'”
- Python报错之:AttributeError: 'NoneType' object has no attribute 'seq'
- AttributeError: 'dict' object has no attribute 'iteritems'
- python遇到AttributeError: 'str' object has no attribute '_getAssertEqualityFunc'问题解决过程
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python3.X识别混合编码,顺便解决“AttributeError: 'module' object has no attribute 'urlopen'”
- python 编译错误TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'
- [python]Django AttributeError 'tuple' object has no attribute 'regex'