Let’s learn how to save array as csv file with Numpy. We will use savetxt method.
Numpy savetxt function let us save Numpy array as text file. We can save an array as comma separated values as well.
To save an array to csv extension file you need to use savetxt file like in the below example.
import numpy as np my_array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]).reshape(3, 3) to_csv = np.savetxt("my_matrix.csv", my_array, delimiter=",")
Checking np.savetxt(“my_matrix.csv”, my_array, delimiter=”,”) you may know the syntax of savetxt method.
Using Numpy savetxt method you can also save your array as the other files like txt.