import numpy as np import pickle from PIL import Image from scipy import misc import pylab import matplotlib.pyplot as plt from scipy import sparse with open('plants_amat.npz','rb') as handle: my_array=pickle.load(handle,encoding='latin1') data1=np.array(my_array) print(my_array.shape) print((my_array[0].data[0])) print(len(my_array[0].rows[0])) matrix=np.zeros((400,400)) print(matrix.shape) for i in range(0,400):#稀疏矩阵的行 zhi=my_array[i].data[0] geshu=len(zhi) col=my_array[i].rows[0] for l in zhi: for c in col: c=int(c) matrix[i][c]=l np.savetxt("matrix.txt",matrix) matrix=np.mat(matrix) plt.imshow(matrix) pylab.show() print('end')