I have a set of matrices as numpy 2d arrays in a list. They are of different sizes (19×19 to 63×63).. Now, I have to arrange them starting from the one with the smallest size to the largest. I am inputting the matrices as below:
pics=[]
templates=[]
c1=0
for c1 in range(1,31):
i1=Image.open("data/"+str(c1)+".gif")
pmat = numpy.asarray(i1)
pics.append(i1)
templates.append(pmat)
Thus, templates is the list that has all the image matrices. pmat of course, contains the images themselves. Is there any easy way to sort this?….
You can sort a list of images by length, see below:
If your image arrays are all square (ie. x-len = y-len) then this should work no problem for your purposes.
EDIT: If you need more flexibility (for non-square images) you can use
key=numpy.size.