Skip to content Skip to sidebar Skip to footer

How To Load Mutiple Ppm Files Present In A Folder As Single Numpy Ndarray?

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

Solution 1:

You could initialize an output array of that shape and once inside the loop, index into the first axis to assign image arrays iteratively -

out = np.empty((K,M,N,3), dtype=np.uint8) # change dtype if neededfor i,filename inenumerate(glob.glob(path+"/*.ppm")):
    # Get img of shape (M,N,3)
    out[i] = img

If you don't know K beforehand, we could get it with len(glob.glob(path+"/*.ppm")).

Post a Comment for "How To Load Mutiple Ppm Files Present In A Folder As Single Numpy Ndarray?"