Adding Axes
newaxis or reshape adds a dimension, useful for broadcasting.
Example
a = np.array([1, 2, 3])
print(a[:, np.newaxis].shape)
print(a[np.newaxis, :].shape)
print(np.expand_dims(a, 0).shape)Result
(3, 1) (1, 3) (1, 3)
Exercise
Add a dimension.
a[:, np.]
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.