从文件中加载ndarray数组
>>> np.loadtxt(textfile) # textfile是文本文件
- 从
.npy
或者.npz
文件中加载ndarray数组np.load
如果是.npy结尾的文件,则返回单个ndarray数组
如果是.npz结尾的文件,则返回一个字典类型对象,{filename: array}
>>> np.load(textfile) # textfile是.npz或.npy结尾的二进制文件
将ndarray数组存入文件
>>> x = np.arange(10)
>>> np.save(outfile, x) # outfile必须以.npy结尾
>>> x = np.arange(10)
>>> y = np.sin(x)
>>> np.savez(outfile, x,y) # outfile必须以.npz结尾
>>> x = np.arange(10)
>>> y = np.sin(x)
>>> np.savetext(outfile, x, delimiter=',') # outfile为文本文件
>>> np.savetext(outfile, (x,y))
>>> np.savetext(outfile, x, fmt='%1.4e')