mars.tensor.squeeze¶
- mars.tensor.squeeze(a, axis=None)[源代码]¶
Remove single-dimensional entries from the shape of a tensor.
- 参数
- 返回
squeezed – The input tensor, but with all or a subset of the dimensions of length 1 removed. This is always a itself or a view into a.
- 返回类型
Tensor
- 引发
ValueError – If axis is not None, and an axis being squeezed is not of length 1
参见
expand_dims
The inverse operation, adding singleton dimensions
reshape
Insert, remove, and combine dimensions, and resize existing ones
实际案例
>>> import mars.tensor as mt
>>> x = mt.array([[[0], [1], [2]]]) >>> x.shape (1, 3, 1) >>> mt.squeeze(x).shape (3,) >>> mt.squeeze(x, axis=0).shape (3, 1) >>> mt.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 >>> mt.squeeze(x, axis=2).shape (1, 3)