Dump a NumPy array into a csv file

前端 未结 10 1264

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

    If you want to save your numpy array (e.g. your_array = np.array([[1,2],[3,4]])) to one cell, you could convert it first with your_array.tolist().

    Then save it the normal way to one cell, with delimiter=';' and the cell in the csv-file will look like this [[1, 2], [2, 4]]

    Then you could restore your array like this: your_array = np.array(ast.literal_eval(cell_string))

提交回复
热议问题