The following Python code creates list of numpy array. I want to load by data sets as a numpy array that has dimension K x M x N x 3
, where K
is the index of the image and M x N x 3
is the dimension of individual image. How can I modify the existing code to do so ?
image_list=[]
for filename in glob.glob(path+"/*.ppm"):
img = imread(filename,mode='RGB')
temp_img = img.reshape(img.shape[0]*img.shape[1]*img.shape[2],1)
image_list.append(temp_img)
You could initialize an output array of that shape and once inside the loop, index into the first axis to assign image arrays iteratively -
If you don't know
K
beforehand, we could get it withlen(glob.glob(path+"/*.ppm"))
.