EEMI

Guided Notes

Reshape, Join & Split

Changing an array's shape, flattening, joining arrays with concatenate and stack, and splitting them.

Reshaping

Slide 1 / 5

reshape() rearranges the same elements into a new shape:

arr = np.arange(1, 13) # 12 elements arr.reshape(4, 3) # 4 rows ร— 3 columns arr.reshape(2, 3, 2) # 3-D

The total number of elements must stay the same: 12 elements fit 4ร—3, 2ร—6, or 2ร—3ร—2, but not 5ร—3.

reshape usually returns a view of the original data, so it's fast even for huge arrays.

โ† Copy vs View & Iterating