Reshaping in NumPy
This lesson explains how to reshape an array into various dimensions.
As explained in the previous lesson, to create a basic NumPy array write:
Z = np.array([0,0,0,0,0,0,0,0,0,0,1,0]
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┏━━━┓───┐
│ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 0 ┃ 1 ┃ 0 │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┗━━━┛───┘
Press + to interact
import numpy as npZ = np.array([0,0,0,0,0,0,0,0,0,0,1,0])print(Z)
We can reshape the array in any dimension
The basic syntax for reshaping array is:
Z=np.array(1D_array).reshape(x_dimension,y_dimension)
Examples
The ...