maxframe.tensor.squeeze#
- maxframe.tensor.squeeze(a, axis=None)[源代码]#
从张量的形状中移除单维度条目。
- 参数:
- 返回:
squeezed -- 输入张量,但所有或部分长度为1的维度已被移除。这始终是 a 本身或 a 的视图。
- 返回类型:
Tensor
- 抛出:
ValueError -- 如果 axis 不为 None,且被压缩的轴长度不为1
参见
expand_dims逆操作,添加单例维度
reshape插入、移除和合并维度,以及调整现有维度的大小
示例
>>> import maxframe.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)