1.5.1 文件输入/输出:scipy.io
载入和保存matlab文件:
In [2]:
from scipy import io as spio
a = np.ones((3, 3))
spio.savemat('file.mat', {'a': a}) # savemat expects a dictionary
data = spio.loadmat('file.mat', struct_as_record=True)
data['a']
Out[2]:
array([[ 1., 1., 1.],
[ 1., 1., 1.],
[ 1., 1., 1.]])
from scipy import misc
misc.imread('fname.png')
# Matplotlib也有类似的方法
import matplotlib.pyplot as plt
plt.imread('fname.png')
更多请见:
- 加载文本文件:numpy.loadtxt()/numpy.savetxt()
- 智能加载文本/csv文件:numpy.genfromtxt()/numpy.recfromcsv()
- 快速有效,但是针对numpy的二进制格式:numpy.save()/numpy.load()