Search⌘ K
AI Features

Reshaping in NumPy

Discover how to reshape one-dimensional NumPy arrays into various multi-dimensional forms. This lesson covers the fundamental reshape method with clear examples of changing arrays to different row and column configurations to enhance your ability to manipulate data structures efficiently.

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 │
   └───┴───┴───┴───┴───┴───┴───┴───┴───┴───┗━━━┛───┘

Python 3.5
import numpy as np
Z = 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 ...