Tsallaka zuwa abun ciki
Justice Tech School

squeeze and swapaxes

squeeze removes length 1 axes and swapaxes exchanges two axes.

Example
a = np.zeros((1, 3, 1))
print(a.squeeze().shape)
b = np.zeros((2, 3, 4))
print(np.swapaxes(b, 0, 2).shape)

Result

(3,)
(4, 3, 2)

Exercise

Remove size 1 axes.

a.()

Quiz Test

What does squeeze remove?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.