12.3.2.1. Shape manipulationΒΆ

import numpy as np


rg = np.random.default_rng(1)
a = np.floor(10 * rg.random((3, 4)))
a

Out:

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

return the array, flattened

a.ravel()

Out:

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

modified shape

a.reshape(6, 2)

Out:

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

transpose

a.T

Out:

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.004 seconds)

Gallery generated by Sphinx-Gallery