简体   繁体   English

如何将Numpy 4D数组保存为CSV?

[英]How to save Numpy 4D array to CSV?

I am trying to save a series of images to CSV file so they can be used as a training dataset for Alexnet Keras machine learning. 我正在尝试将一系列图像保存到CSV文件,以便它们可用作Alexnet Keras机器学习的训练数据集。 The shape is (15,224,224,3). 形状为(15,224,224,3)。

So far I am having issue doing this. 到目前为止,我在执行此操作时遇到问题。 I have managed to put all data into a numpy array but now I cannot save it to a file. 我已经设法将所有数据放入一个numpy数组中,但是现在我无法将其保存到文件中。

Please help. 请帮忙。

I don't think saving it to a csv file is the correct way to do this, it's used for 1d or 2d data to create a table-like structure, so I'm going to offer another solution. 我不认为将其保存到csv文件中是正确的方法,它用于1d或2d数据来创建类似表格的结构,因此我将提供另一种解决方案。 You can use np.save to save any numpy array to a file; 您可以使用np.save将任何numpy数组保存到文件。

np.save('file_name', your_array)

which can then be loaded using np.load ; 然后可以使用np.load加载np.load

loaded_array = np.load('file_name.npy')

Hope that this works for you. 希望这对您有用。

You can try using pickle to save the data. 您可以尝试使用泡菜保存数据。 It is much more diverse and easy to handle compare to np.save. 与np.save相比,它更加多样化且易于处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM