mindspore/docs/api/api_python/ops/mindspore.ops.Reshape.rst

36 lines
1.1 KiB
ReStructuredText
Raw Normal View History

2021-12-04 13:55:42 +08:00
mindspore.ops.Reshape
======================
.. py:class:: mindspore.ops.Reshape(*args, **kwargs)
基于给定的shape使用相同的值对输入Tensor进行reshape操作。
`input_shape` 最多只能有一个-1在这种情况下它可以从剩余的维度和输入的元素个数中推断出来。
**输入:**
- **input_x** (Tensor) - Tensor的shape为 :math:`(x_1, x_2, ..., x_R)`
- **input_shape** (tuple[int]) - 输入tuple由多个整数构成:math:`(y_1, y_2, ..., y_S)` 。只支持常量值。
**输出:**
Tensor其shape为 :math:`(y_1, y_2, ..., y_S)`
**异常:**
2021-12-04 19:03:07 +08:00
- **ValueError** - 给定的 `input_shape`,如果它有几个-1或者其元素的乘积小于或等于0或者无法被输入Tensor的shape的乘积相除或者与输入的数组大小不匹配。
2021-12-04 13:55:42 +08:00
**支持平台:**
``Ascend`` ``GPU`` ``CPU``
**样例:**
>>> input_x = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]), mindspore.float32)
>>> reshape = ops.Reshape()
>>> output = reshape(input_x, (3, 2))
>>> print(output)
[[-0.1 0.3]
[ 3.6 0.4]
[ 0.5 -3.2]]