pypto.unsqueeze#

产品支持情况#

产品

是否支持

Ascend 950PR/Ascend 950DT

Atlas A3 训练系列产品/Atlas A3 推理系列产品

Atlas A2 训练系列产品/Atlas A2 推理系列产品

功能说明#

为输入Tensor增加维度。

函数原型#

unsqueeze(input: Tensor, dim: int) -> Tensor

参数说明#

参数名

输入/输出

说明

input

输入

源操作数。
支持的数据类型为:PyPto支持的数据类型
不支持空Tensor;Shape Size不大于2147483647(即INT32_MAX)。

dim

输入

指定插入新维度的位置(索引)。
支持负索引。
需在 [-input.dim - 1, input.dim] 范围内。

返回值说明#

返回在指定维度dim处新增大小为1的维度的输出Tensor,与输入Tensor共享数据且属性一致。

调用示例#

x = pypto.tensor([2, 3], pypto.DT_FP32)
y = pypto.unsqueeze(x, 0)

结果示例如下:

输出数据x: [[1, 2, 3],
            [4, 5, 6]]
输出数据y: [[[1, 2, 3],
             [4, 5, 6]]]