How to change array shapes in in numpy?

You can assign a shape tuple directly to numpy.ndarray.shape.

A.shape = (3,1)

As of 2022, the docs state:

Setting arr.shape is discouraged and may be deprecated in the future.
Using ndarray.reshape is the preferred approach.

The current best solution would be

A = np.reshape(A, (3,1))

Leave a Comment