I am adding 3000 np.arrays to a list and converting the list back to np.array. The dimension of the np.array is (270000,). After the entire run of the loop and post np.array conversion process, the dimension of the resultant array is : (3000,) while it's expected to be (3000,270000). The weird thing is that on stopping the process midway, say at 1900 arrays, the observed shape is (1900,270000) which is how I want the output to be at the end of the loop.
from scipy import misc
from os import walk
labels = []
X=[]
Y=[]
for (_, dirnames, _) in walk(mypath):
labels.extend(dirnames)
for category, label in enumerate(labels):
# print 'Category:',category,'\tLabel:',label
for root, dirs, files in os.walk(os.path.abspath(join(mypath,label))):
for file in files:
imagePath=os.path.join(root, file)
face = misc.imread(imagePath)
flattenImgMatrix=misc.imresize(face,[300, 300], interp='nearest').flatten()
X.append(flattenImgMatrix)
Y.append([category])
arrX=np.array(X)
arrY=np.array(Y)
object. This happens when numpy can't infer enough about those shapes inside to create a numerical array on the outside. Often people feed this with unequal-shaped images, but it seems you care about that. Also keep in mind, that your code is incomplete (e.g. misc: skimage, scipy, imageio, matplotlib?) and we can only guess! - saschaimresize, and (810000,) after flattening. - hpaulj