Saving and Loading
save and load keep arrays in .npy files. savetxt and loadtxt use text.
Example
import io
a = np.arange(6).reshape(2, 3)
buf = io.BytesIO()
np.save(buf, a)
buf.seek(0)
print(np.load(buf))
t = io.StringIO()
np.savetxt(t, a, fmt="%d", delimiter=",")
print(t.getvalue().strip())Result
[[0 1 2] [3 4 5]] 0,1,2 3,4,5
Exercise
Load a file.
np.("a.npy")
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.