mindspore.numpy.expand_dims
- mindspore.numpy.expand_dims(a, axis)[源代码]
- 扩展Tensor的shape。在扩展后的Tensor的shape中插入一个新轴,该轴将出现在指定的位置。 - 参数:
- a (Tensor) - 输入Tensor数组。 
- axis (Union[int, list(int), tuple(int)]) - 新轴在扩展轴中的位置。 
 
- 返回:
- Tensor,指定轴位置的维度数增加后的Tensor。 
- 异常:
- TypeError - 如果输入参数非上述给定的类型。 
- ValueError - 如果 - axis超出了- a.ndim。
 
- 支持平台:
- Ascend- GPU- CPU
 - 样例: - >>> import mindspore.numpy as np >>> x = np.ones((2,2)) >>> x = np.expand_dims(x,0) >>> print(x.shape) (1, 2, 2)