Dump a NumPy array into a csv file

前端 未结 10 1256

Is there a way to dump a NumPy array into a CSV file? I have a 2D NumPy array and need to dump it in human-readable format.

10条回答
  •  自闭症患者
    2020-11-22 13:18

    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)

提交回复
热议问题