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

Function expand_dims

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

r"""Adds dimension before given axis. Args: inp: input tensor. axis: place of new axes. Returns: output tensor. Examples: >>> import numpy as np >>> x = Tensor([1, 2]) >>> out = F.expand_dims(x, 0) >>> out.numpy().shape (

(inp: Tensor, axis: Union[int, Sequence[int]])

Source from the content-addressed store, hash-verified

1047
1048
1049def expand_dims(inp: Tensor, axis: Union[int, Sequence[int]]) -> Tensor:
1050 r"""Adds dimension before given axis.
1051
1052 Args:
1053 inp: input tensor.
1054 axis: place of new axes.
1055
1056 Returns:
1057 output tensor.
1058
1059 Examples:
1060 >>> import numpy as np
1061 >>> x = Tensor([1, 2])
1062 >>> out = F.expand_dims(x, 0)
1063 >>> out.numpy().shape
1064 (1, 2)
1065 """
1066
1067 return expand_dims_cpp(inp, axis)
1068
1069
1070def squeeze(inp: Tensor, axis: Optional[Union[int, Sequence[int]]] = None) -> Tensor:

Callers 5

forwardMethod · 0.90
multi_head_attentionFunction · 0.70
interpolateFunction · 0.70
topkFunction · 0.70
stackFunction · 0.70

Calls

no outgoing calls

Tested by 1

forwardMethod · 0.72