提交 86ee4638 编写于 作者: M Megvii Engine Team

Merge pull request #402 from AA1HSHH:docstring-reshape

GitOrigin-RevId: 1ec572eb7cba4dad657e02b51da4312ef04943bb
...@@ -856,31 +856,30 @@ def transpose(inp: Tensor, pattern: Iterable[int]) -> Tensor: ...@@ -856,31 +856,30 @@ def transpose(inp: Tensor, pattern: Iterable[int]) -> Tensor:
def reshape(inp: Tensor, target_shape: Iterable[int]) -> Tensor: def reshape(inp: Tensor, target_shape: Iterable[int]) -> Tensor:
r"""Reshapes a tensor to given target shape; total number of logical elements must r"""Reshapes a tensor without changing its data.
remain unchanged
Args: Args:
inp: input tensor. inp: input tensor to reshape.
target_shape: target shape, it can contain an element of -1 representing ``unspec_axis``. target_shape: target shape compatible with the original shape. One shape dimension is allowed
to be `-1` . When a shape dimension is `-1` , the corresponding output tensor shape dimension
Examples: must be inferred from the length of the tensor and the remaining dimensions.
.. testcode::
import numpy as np
from megengine import tensor
import megengine.functional as F
x = tensor(np.arange(12, dtype=np.int32))
out = F.reshape(x, (3, 4))
print(out.numpy())
Outputs: Returns:
an output tensor having the same data type, elements, and underlying element order as `inp` .
.. testoutput:: Examples:
[[ 0 1 2 3] >>> x = F.arange(12)
[ 4 5 6 7] >>> x
[ 8 9 10 11]] Tensor([ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.], device=xpux:0)
>>> F.reshape(x, (3, 4))
Tensor([[ 0. 1. 2. 3.]
[ 4. 5. 6. 7.]
[ 8. 9. 10. 11.]], device=xpux:0)
>>> F.reshape(x, (2, -1))
Tensor([[ 0. 1. 2. 3. 4. 5.]
[ 6. 7. 8. 9. 10. 11.]], device=xpux:0)
""" """
return inp.reshape(target_shape) return inp.reshape(target_shape)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册