mindspore.ops.expand

mindspore.ops.expand(input_x, size)[source]

Returns a new view of the self tensor with singleton dimensions expanded to a larger size.

Note

Passing -1 as the size for a dimension means not changing the size of that dimension. Tensor can be also expanded to a larger number of dimensions, and the new ones will be appended at the front. For the new dimensions, the size cannot be set to -1.

Parameters
  • input_x (Tensor) – The shape of tensor is (x_1, x_2, …, x_R).

  • size (Tensor) – The expanded shape of input_x.

Returns

y (Tensor) - Tensor after expansion whose shape is size.

Raises
  • TypeError – If input_x or size is not Tensor.

  • TypeError – If the type of size is not one of the following dtype: int16, int32, int64.

  • ValueError – If the size of size is less than the size of input_x.shape.

  • ValueError – If size is not a 1-D tensor.

  • ValueError – If the expanded size is not equal to the existing shape of input_x at a dimension that is not 1.

  • ValueError – If the expanded size < 0 and it is in a leading position, corresponding to a non-existing dimension in input_x.

  • ValueError – If the number of elements of output is more than 1000000.

Supported Platforms:

Ascend CPU

Examples

>>> input_x = Tensor(np.array([[1], [2], [3]]), mindspore.float32)
>>> size = Tensor(np.array([3,4]), mindspore.int32)
>>> y = ops.expand(input_x, size)
>>> print(y)
[[1. 1. 1. 1.]
 [2. 2. 2. 2.]
 [3. 3. 3. 3.]]