mindspore.ops.unbind

mindspore.ops.unbind(x, dim=0)[source]

Removes a tensor dimension in specified axis.

Unstacks a tensor of rank R along axis dimension, and output tensors will have rank (R-1).

Given a tensor of shape \((x_1, x_2, ..., x_R)\). If \(0 \le axis\), the shape of tensor in output is \((x_1, x_2, ..., x_{axis}, x_{axis+2}, ..., x_R)\).

Parameters
  • x (Tensor) – The shape is \((x_1, x_2, ..., x_R)\). A tensor to be unstacked and the rank of the tensor must be greater than 0.

  • dim (int) – Dimension along which to unpack. Negative values wrap around. The range is [-R, R). Default: 0.

Returns

A tuple of tensors, the shape of each objects is the same.

Raises

ValueError – If axis is out of the range [-R, R).

Supported Platforms:

Ascend GPU CPU

Examples

>>> x = Tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))
>>> output = ops.unbind(x, dim=0)
>>> print(output)
(Tensor(shape=[3], dtype=Int64, value=[1, 2, 3]), Tensor(shape=[3], dtype=Int64, value=[4, 5, 6]),
Tensor(shape=[3], dtype=Int64, value=[7, 8, 9]))