Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Numpy:将阵列数据存储到文件_Python_Python 3.x_Numpy_File - Fatal编程技术网

Python Numpy:将阵列数据存储到文件

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

因此,我有两个数组,需要将它们写入一个名为“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)
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标准库来解决问题