I have 60000 train_images brought in as a shape (28,28,60000) matrix. It is a numpy.ndarray. I want to convert it to an array of 1 dimensional images, meaning each image is represented as a single line/array of numbers, and I want 60000 arrays. In other words, I want to go from (28, 28, 60000) to (60000, 28*28). In python, it would be:
images_features = []
for image in images:
imageLine = []
for y in range(len(image)):
for x in range(len(image[0])):
imageLine.append(image[y][x])
images_features.append(imageLine)
How can I do this? I suspect that I need to use reshape but I couldn't figure out how exactly I can do this.
This is how I'm getting the images:
data = scipy.io.loadmat('train.mat')
images = data["train_images"]
So the "images" is the array I'm talking about.
Someone suggested to me that:
"You may need to change axes or combine them do get the functionality you want. I recommend plotting them as well in case an image ends up sideways. Make sure you are diligent with your axes to avoid further problems there."
I have no idea what "axes" is being referred to here and how to take what's said above into account.
Can someone explain what I need to do and why? (What it does)
images.reshape(-1).tolist()if you want the output to be a python list (or withouttolist()otherwise)? - mgc-1flatten completely the matrix (which is not what you want). You can take a look at the numpy documentation aboutN-dimensional array- mgcimages.reshape(-1, 60000)will do the job ? Giving you 60000 features with 784 values. To have the output as a python list of 60000 features :images.reshape(-1, 60000).T.tolist()- mgcimage.transpose(2,0,1)orimage.transpose(2,1,0)? - Divakar