Raising dimension of an array using np.squeeze equivalent

Viewed 12

I want to use a np.squeeze equivalent for raising the dimension of A from (1,3) to (1,1,3). Does there exist such an equivalent?

import numpy as np

A=np.array([[1,2,3]])
print(A.shape)
1 Answers

Use reshape (docs)

A = np.array([[1, 2, 3]])
print(A.shape)  # (1, 3)
B = A.reshape((1, 1, 3))
print(B.shape)  # (1, 1, 3)
Related