Dump a NumPy array into a csv file

前端 未结 10 1131

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:30

    You can also do it with pure python without using any modules.

    # format as a block of csv text to do whatever you want
    csv_rows = ["{},{}".format(i, j) for i, j in array]
    csv_text = "\n".join(csv_rows)
    
    # write it to a file
    with open('file.csv', 'w') as f:
        f.write(csv_text)
    

提交回复
热议问题