12.3.10.2.1. Shape manipulationΒΆ

import numpy as np


rg = np.random.default_rng(1)
a = np.floor(10 * rg.random((3, 4)))
a
array([[5., 9., 1., 9.],
       [3., 4., 8., 4.],
       [5., 0., 7., 5.]])

return the array, flattened

a.ravel()
array([5., 9., 1., 9., 3., 4., 8., 4., 5., 0., 7., 5.])

modified shape

a.reshape(6, 2)
array([[5., 9.],
       [1., 9.],
       [3., 4.],
       [8., 4.],
       [5., 0.],
       [7., 5.]])

transpose

a.T
array([[5., 3., 5.],
       [9., 4., 0.],
       [1., 8., 7.],
       [9., 4., 5.]])
a.resize(2, 6)

Total running time of the script: ( 0 minutes 0.005 seconds)