numpy.fromfile
According to SciPy documentation
Construct an array from data in a text or binary file. [...] Data written using the
tofilemethod can be read using this function.
So I just follow the instruction and create a file by using tofile
import numpy as np
A = np.random.rand(1000)
A.tofile('binary_file') # saving a dummy binary_file
x1 = np.fromfile('binary_file') # loading the dummy file
print(np.array_equal(A, x1)) # checking if the arrays are the same
>>> True
numpy.load
At the same time, we also have np.save and np.load, which do exactly the save job as tofile and fromfile
np.save('file.npy',A)
x2 = np.load('file.npy')
print(np.array_equal(A, x1))
>>> True
fromfile == np.load?
The two loading methods yield to same result as demonstrated below
print(np.array_equal(x1, x2))
>>> True
Then why do need both functions? Anything that can be done on np.load but not fromfile? Or vice versa?