How to save Numpy 4D array to CSV?

Question:

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. The shape is (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.

Please help.

Asked By: Science Lover

||

Answers:

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. You can use np.save to save any numpy array to a file;

np.save('file_name', your_array)

which can then be loaded using np.load;

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

Hope that this works for you.

Answered By: dennissv

You can try using pickle to save the data. It is much more diverse and easy to handle compare to np.save.

Answered By: lifeisshubh
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.