Tutorial by Examples

x = np.random.random([100,100]) x.tofile('/path/to/dir/saved_binary.npy') y = fromfile('/path/to/dir/saved_binary.npy') z = y.reshape(100,100) all(x==z) # Output: # True
The function np.loadtxt can be used to read csv-like files: # File: # # Col_1 Col_2 # 1, 1 # 2, 4 # 3, 9 np.loadtxt('/path/to/dir/csvlike.txt', delimiter=',', comments='#') # Output: # array([[ 1., 1.], # [ 2., 4.], # [ 3., 9.]]) The same file could be read ...
Analog to np.loadtxt, np.savetxt can be used to save data in an ASCII file import numpy as np x = np.random.random([100,100]) np.savetxt("filename.txt", x) To control formatting: np.savetxt("filename.txt", x, delimiter=", " , newline="\n", comment...
Three main functions available (description from man pages): fromfile - A highly efficient way of reading binary data with a known data-type, as well as parsing simply formatted text files. Data written using the tofile method can be read using this function. genfromtxt - Load data from a t...

Page 1 of 1