All problems

Reshaping a Flat List Into a Grid

easyPythonNumPyreshape

The line-scan camera at Larkspur Labs writes each picture to disk as one long strip of brightness values with nothing in it to mark where a line of the picture ends; the line length is recorded separately in a header. A viewer therefore has to fold the strip back into a picture before anything can be seen. The fold follows the order the camera scanned in: the first cols values are the top row of the picture, the next cols values are the row beneath it, and so on to the bottom.

Task: Print the picture as a grid.

Input

The first line holds the strip: 12 whole numbers separated by single spaces. The second line holds two integers separated by a space — the number of rows and the number of columns the header calls for. Their product is the length of the strip.

Output

rows lines, each holding cols values separated by single spaces, folded in the order described above. Each value is a plain integer.

Example:

Input:
1 2 3 4 5 6 7 8 9 10 11 12
3 4

Output:
1 2 3 4
5 6 7 8
9 10 11 12

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…