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

Function broadcast_to

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

r"""Broadcasts a tensor to given shape. Args: inp: input tensor. shape: target shape. Returns: output tensor. Examples: >>> import numpy as np >>> data = Tensor(np.arange(0, 3, dtype=np.float32).reshape(3)) >>> out = F.broadcast_to(data,

(inp: Tensor, shape: Union[int, Iterable[int]])

Source from the content-addressed store, hash-verified

541
542
543def broadcast_to(inp: Tensor, shape: Union[int, Iterable[int]]) -> Tensor:
544 r"""Broadcasts a tensor to given shape.
545
546 Args:
547 inp: input tensor.
548 shape: target shape.
549
550 Returns:
551 output tensor.
552
553 Examples:
554 >>> import numpy as np
555 >>> data = Tensor(np.arange(0, 3, dtype=np.float32).reshape(3))
556 >>> out = F.broadcast_to(data, (2, 3))
557 >>> out.numpy()
558 array([[0., 1., 2.],
559 [0., 1., 2.]], dtype=float32)
560 """
561 return broadcast_cpp(inp, shape)
562
563
564def concat(inps: Iterable[Tensor], axis: int = 0, device=None) -> Tensor:

Callers 11

topk_accuracyFunction · 0.70
ctc_lossFunction · 0.70
_merge_masksFunction · 0.70
interpolateFunction · 0.70
isnanFunction · 0.70
isinfFunction · 0.70
fullFunction · 0.70
_get_idxFunction · 0.70
repeatFunction · 0.70
_tile_one_dimFunction · 0.70
tileFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected