mindspore.numpy.stack

mindspore.numpy.stack(arrays, axis=0)[源代码]

Joins a sequence of arrays along a new axis.

The axis parameter specifies the index of the new axis in the dimensions of the result. For example, if axis=0 it will be the first dimension and if axis=-1 it will be the last dimension.

说明

Numpy argument out is not supported.

参数
  • arrays (sequence of Tensor) – Each array must have the same shape.

  • axis (int, optional) – The axis in the result array along which the input arrays are stacked. Default: 0.

返回

Tensor, The stacked array has one more dimension than the input arrays.

异常

ValueError – If input is not Tensor, tuple, or list.

Supported Platforms:

Ascend GPU CPU

样例

>>> import mindspore.numpy as np
>>> arrays = [np.ones((3, 4)) for _ in range(10)]
>>> output = np.stack(arrays, axis=0)
>>> print(output.shape)
(10, 3, 4)
>>> output = np.stack(arrays, axis=1)
>>> print(output.shape)
(3, 10, 4)
>>> output = np.stack(arrays, axis=2)
>>> print(output.shape)
(3, 4, 10)