Answers for "how to save numpy array to a file"

2

how to write a numpy array to a file in python

numpy.savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', 
              header='', footer='', comments='# ', encoding=None)


x = y = z = np.arange(0.0,5.0,1.0)
np.savetxt('test.out', x, delimiter=',')   # X is an array
np.savetxt('test.out', (x,y,z))   # x,y,z equal sized 1D arrays
np.savetxt('test.out', x, fmt='%1.4e')   # use exponential notation
Posted by: Guest on March-15-2021
0

save set of numpy arrays to file py

>>> with open('test.npy', 'wb') as f:
		np.save(f, np.array([1, 2]))
		np.save(f, np.array([1, 3]))
>>> with open('test.npy', 'rb') as f:
		a = np.load(f)
		b = np.load(f)
>>> print(a, b)
# [1 2] [1 3]
Posted by: Guest on May-31-2021

Code answers related to "how to save numpy array to a file"

Python Answers by Framework

Browse Popular Code Answers by Language