MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / reshape

Function reshape

imperative/python/megengine/functional/tensor.py:996–1020  ·  view source on GitHub ↗

r"""Reshapes a tensor without changing its data. Args: inp: input tensor to reshape. 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 di

(inp: Tensor, target_shape: Iterable[int])

Source from the content-addressed store, hash-verified

994
995
996def reshape(inp: Tensor, target_shape: Iterable[int]) -> Tensor:
997 r"""Reshapes a tensor without changing its data.
998
999 Args:
1000 inp: input tensor to reshape.
1001 target_shape: target shape compatible with the original shape. One shape dimension is allowed
1002 to be `-1` . When a shape dimension is `-1` , the corresponding output tensor shape dimension
1003 must be inferred from the length of the tensor and the remaining dimensions.
1004
1005 Returns:
1006 an output tensor having the same data type, elements, and underlying element order as `inp` .
1007
1008 Examples:
1009 >>> x = F.arange(12)
1010 >>> x
1011 Tensor([ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.], device=xpux:0)
1012 >>> F.reshape(x, (3, 4))
1013 Tensor([[ 0. 1. 2. 3.]
1014 [ 4. 5. 6. 7.]
1015 [ 8. 9. 10. 11.]], device=xpux:0)
1016 >>> F.reshape(x, (2, -1))
1017 Tensor([[ 0. 1. 2. 3. 4. 5.]
1018 [ 6. 7. 8. 9. 10. 11.]], device=xpux:0)
1019 """
1020 return inp.reshape(target_shape)
1021
1022
1023def flatten(inp: Tensor, start_axis: int = 0, end_axis: int = -1) -> Tensor:

Callers 2

_merge_masksFunction · 0.70
interpolateFunction · 0.70

Calls 1

reshapeMethod · 0.45

Tested by

no test coverage detected