How to deal with this when I use numpy.array() to deal with 'list'?

Clash Royale CLAN TAG#URR8PPPHow to deal with this when I use numpy.array() to deal with 'list'?
import cv2
import numpy
list_pixel=
list_label=
for i in range(0,10):
for j in range(0,10):
list_pixel.append(cv2.imread("C:\Users\kimcho\Desktop\testdata\testdata_"+str(i)+"_0"+str(j)+".png",0))
list_label.append(i)
j=0
list_pixel.pop(0)
list_label.pop(0)
list_pixel=numpy.array(list_pixel)
print(list_pixel)
print(list_pixel.shape)
print(list_pixel[0].shape)
How to deal with this when I use numpy.array() to deal with 'list'?I wanna make datasets by imitating keras.But,the datasets I made didn't satisfy me.I want it to act like keras,to return a value like this:

It can return a value of(60000,28,28)
But as for my datasets,it can only return like this:

Only return a value of(99,)—— I got 99 pictures and I want to load their pixel into list_pixel
Here is my code:

Hoping anyone can help me solve this problem.Deeply thank you!!!
sorry,this is my first time to use stackoverflow.I dont know how you edit it like a code format to show it in a screen
– kimcho
2 hours ago
import cv2 import numpy list_pixel= list_label= for i in range(0,10): for j in range(0,10): list_pixel.append(cv2.imread("C:\Users\kimcho\Desktop\testdata\testdata_"+str(i)+"_0"+str(j)+".png",0)) list_label.append(i) j=0 list_pixel.pop(0) list_label.pop(0) numpy.array(list_pixel) print(list_pixel) print(list_pixel.shape) print(list_pixel[0].shape)
– kimcho
2 hours ago
Please put your code in the question, NOT in a comment. It is really hard to read this way.
– Luca Cappelletti
1 hour ago
My bad,sir.That's all right there.Thanks
– kimcho
1 hour ago
1 Answer
1
When using cv2.imread you already load the image as a numpy array.
cv2.imread
A simple approach to it is the following:
import cv2
import numpy as np
list_label = np.arange(0, 10)
path = "C:\Users\kimcho\Desktop\testdata\testdata_{0}_0{1}.png"
list_pixel = np.array([
cv2.imread(path.format(i, j), 0) for i in range(0, 10)
for j in range(0, 10)
])
Let's try it on a simple scenario: we suppose there is just an image 28x28 in size, such as this one:

Let's say it is in the path my/path/image.png.
my/path/image.png
import cv2
import numpy as np
list_label = np.arange(0, 10)
path = "my/path/image.png"
list_pixel = np.array([
cv2.imread(path,0) for i in range(0, 10)
for j in range(0, 10)
])
When running list_pixel.shape you get (100, 28, 28).
list_pixel.shape
(100, 28, 28)
sorry,sir. When I use your method and use "print(list_pixel.shape)", it only shows me that its shape is (100,),which still not satisfies my need.I wanna it to be like (100,28,28) and I dont figure out a way to do that.SO, do you have another idea?
– kimcho
8 mins ago
I have added a working example. Are you sure all your images are 28x28? Typically shapes such as (x,) in matrices are caused by different sizes in rows, so that they are treated as a list instead than as a matrix.
– Luca Cappelletti
42 secs ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Would you please type your code here, instead of putting screenshots?
– kitman0804
3 hours ago