Dump a NumPy array into a csv file
Solution 1:
numpy.savetxt
saves an array to a text file.
import numpy
a = numpy.asarray([ [1,2,3], [4,5,6], [7,8,9] ])
numpy.savetxt("foo.csv", a, delimiter=",")
Solution 2:
You can use pandas
. It does take some extra memory so it's not always possible, but it's very fast and easy to use.
import pandas as pd
pd.DataFrame(np_array).to_csv("path/to/file.csv")
if you don't want a header or index, use to_csv("/path/to/file.csv", header=None, index=None)