First page Back Continue Last page Overview Graphics

New Dimensions

The dimension of an array can be extended with the method newaxis:

>>> x = np.array([1,3,5,17,23])

>>> x

array([ 1, 3, 5, 17, 23])

>>> y = x[:, np.newaxis]

>>> y

array([[ 1],

[ 3],

[ 5],

[17],

[23]])

>>> y[0,0]

1

>>> y[4,0]

23

>>> x[np.newaxis,:]

array([[ 1, 3, 5, 17, 23]])