Puzzle

The Numpy functions vstack and hstack concatenate arrays.

image0

Assemble the complete picture from the images in pieces.zip.

Here is the code that assembles two of the pieces:


from PIL import Image
import numpy as np

a = np.array(Image.open('a.png'))
b = np.array(Image.open('b.png'))
print(a.shape, b.shape)

im = np.vstack([a,b])  # vertical merge (correct)
print(im.shape)
Image.fromarray(im).save('vertical.png')

im = np.hstack([a,b])  # horizontal merge (WRONG)
print(im.shape)
Image.fromarray(im).save('horizontal.png')

Hints

  • the functions np.vstack and np.hstack accept a list of NumPy arrays

  • one dimension of the arrays needs to be identical

  • use print(x.shape) a lot

  • the order in which you assemble matters


Challenge

Create your own puzzle. In make_pieces.py you find code that was used to create pieces.