Dumping a NumPy Array into a CSV File
Exporting multidimensional NumPy arrays to CSV files is a common requirement for data manipulation and analysis. This question explores the use of NumPy's savetxt function to achieve this task.
Solution
NumPy provides the savetxt function, which offers a convenient method for writing arrays to a text file in the comma-separated values (CSV) format.
import numpy # Create a 2D NumPy array a = numpy.asarray([ [1,2,3], [4,5,6], [7,8,9] ]) # Save array to CSV file numpy.savetxt("foo.csv", a, delimiter=",")
Explanation
The above is the detailed content of How to export a multidimensional NumPy array to a CSV file?. For more information, please follow other related articles on the PHP Chinese website!