I am a beginner in python and I am trying to apply Principal Component Analysis (PCA) to a set of images. I want to put the images in a matrix to be able to perform PCA. I am still at the beginning but I am having errors.
import numpy as np
#insert images to matrix
dirname = 'C:\Users\Karim\Downloads\shp_marcel_train\Marcel-Train\A'
X = [np.asarray(Image.open(os.path.join(dirname, fn))) for fn in os.listdir(dirname)]
num_data,dim = X.shape
AttributeError: 'list' object has no attribute 'shape'
When you do
[np.asarray(Image.open(os.path.join(dirname, fn))) for fn in os.listdir(dirname)]
It would return an array, which is stored in local variable
You are trying to extract variables from a list, and hence the error.
The individual elements within
X have the shape attributes. Hence, you need to do something like this (modify it according to the datastructure
shape is defined as )
dim0 = X.shape and so on