import numpy as np
import matplotlib.pyplot as plt
def gallery(array, ncols=3):
nindex, height, width, intensity = array.shape
nrows = nindex//ncols
assert nindex == nrows*ncols
result = (array.reshape(nrows, ncols, height, width, intensity)
.swapaxes(1,2)
.reshape(height*nrows, width*ncols, intensity))
return result
def make_array():
from PIL import Image
return np.array([np.asarray(Image.open('face.png').convert('RGB'))]*12)
array = make_array()
result = gallery(array)
plt.imshow(result)
plt.show()
gives 
(nrows*ncols, height, weight, intensity)
. (height*nrows, width*ncols, intensity)
.
, , reshape
: nrows
ncols
:
array.reshape(nrows, ncols, height, width, intensity)
swapaxes(1,2)
, (nrows, height, ncols, weight, intensity)
. , nrows
height
ncols
width
.
reshape
, reshape(height*nrows, width*ncols, intensity)
.
( ) , , unblockshaped
.