dask.array.squeeze — Dask documentation (original) (raw)

Remove axes of length one from a.

This docstring was copied from numpy.squeeze.

Some inconsistencies with the Dask version may exist.

import numpy as np
x = np.array([[[0], [1], [2]]])
x.shape
(1, 3, 1) np.squeeze(x).shape
(3,) np.squeeze(x, axis=0).shape
(3, 1) np.squeeze(x, axis=1).shape
Traceback (most recent call last): ... ValueError: cannot select an axis to squeeze out which has size not equal to one np.squeeze(x, axis=2).shape
(1, 3) x = np.array([[1234]])
x.shape
(1, 1) np.squeeze(x)
array(1234) # 0d array np.squeeze(x).shape
() np.squeeze(x)[()]
1234