0

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)
user19862793
  • 169
  • 6
  • `A[None, :]` or `A[:, None, :]` – Ali_Sh Sep 07 '22 at 13:06
  • 1
    Does this answer your question? [Efficient way to add a singleton dimension to a NumPy vector so that slice assignments work](https://stackoverflow.com/questions/9510252/efficient-way-to-add-a-singleton-dimension-to-a-numpy-vector-so-that-slice-assig) – Ali_Sh Sep 07 '22 at 13:08

1 Answers1

1

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)
Ofer Sadan
  • 11,391
  • 5
  • 38
  • 62