1.5.1 文件输入/输出:scipy.io

载入和保存matlab文件:

In [2]:

  1. from scipy import io as spio
  2. a = np.ones((3, 3))
  3. spio.savemat('file.mat', {'a': a}) # savemat expects a dictionary
  4. data = spio.loadmat('file.mat', struct_as_record=True)
  5. data['a']

Out[2]:

  1. array([[ 1., 1., 1.],
  2. [ 1., 1., 1.],
  3. [ 1., 1., 1.]])
  1. from scipy import misc
  2. misc.imread('fname.png')
  3. # Matplotlib也有类似的方法
  4. import matplotlib.pyplot as plt
  5. plt.imread('fname.png')

更多请见: