Python Numpy:将阵列数据存储到文件
因此,我有两个数组,需要将它们写入一个名为“output.dat”的文件中,这样我就可以从该文件中的每个数组中读取数据,并使用pyplot绘制数据。可以使用Python Numpy:将阵列数据存储到文件,python,python-3.x,numpy,file,Python,Python 3.x,Numpy,File,因此,我有两个数组,需要将它们写入一个名为“output.dat”的文件中,这样我就可以从该文件中的每个数组中读取数据,并使用pyplot绘制数据。可以使用numpy.save()函数存储该文件,如下所示: x = np.array([1, 2, 3, 4]) # Note: The standard convention is to store as a .npy file. with open('output.dat', 'wb') as f: np.save(f, x) wit
numpy.save()
函数存储该文件,如下所示:
x = np.array([1, 2, 3, 4])
# Note: The standard convention is to store as a .npy file.
with open('output.dat', 'wb') as f:
np.save(f, x)
with open('output.dat', 'rb') as f:
x = np.load(f)
>>> array([1, 2, 3, 4])
numpy.load()
函数可用于检索文件,如下所示:
x = np.array([1, 2, 3, 4])
# Note: The standard convention is to store as a .npy file.
with open('output.dat', 'wb') as f:
np.save(f, x)
with open('output.dat', 'rb') as f:
x = np.load(f)
>>> array([1, 2, 3, 4])
.函数numpy.save()
可用于存储文件,如下所示:
x = np.array([1, 2, 3, 4])
# Note: The standard convention is to store as a .npy file.
with open('output.dat', 'wb') as f:
np.save(f, x)
with open('output.dat', 'rb') as f:
x = np.load(f)
>>> array([1, 2, 3, 4])
numpy.load()
函数可用于检索文件,如下所示:
x = np.array([1, 2, 3, 4])
# Note: The standard convention is to store as a .npy file.
with open('output.dat', 'wb') as f:
np.save(f, x)
with open('output.dat', 'rb') as f:
x = np.load(f)
>>> array([1, 2, 3, 4])
通常,如果您提供了一些试图解决问题的证据,您可以使用pickle标准库来解决问题。通常,如果您提供了一些试图解决问题的证据,您可以使用pickle标准库来解决问题