MCPcopy Index your code
hub / github.com/numpy/numpy / broadcast_to

Function broadcast_to

numpy/lib/_stride_tricks_impl.py:475–517  ·  view source on GitHub ↗

Broadcast an array to a new shape. Parameters ---------- array : array_like The array to broadcast. shape : tuple or int The shape of the desired array. A single integer ``i`` is interpreted as ``(i,)``. subok : bool, optional If True, then sub-cl

(array, shape, subok=False)

Source from the content-addressed store, hash-verified

473
474@array_function_dispatch(_broadcast_to_dispatcher, module='numpy')
475def broadcast_to(array, shape, subok=False):
476 """Broadcast an array to a new shape.
477
478 Parameters
479 ----------
480 array : array_like
481 The array to broadcast.
482 shape : tuple or int
483 The shape of the desired array. A single integer ``i`` is interpreted
484 as ``(i,)``.
485 subok : bool, optional
486 If True, then sub-classes will be passed-through, otherwise
487 the returned array will be forced to be a base-class array (default).
488
489 Returns
490 -------
491 broadcast : array
492 A readonly view on the original array with the given shape. It is
493 typically not contiguous. Furthermore, more than one element of a
494 broadcasted array may refer to a single memory location.
495
496 Raises
497 ------
498 ValueError
499 If the array is not compatible with the new shape according to NumPy's
500 broadcasting rules.
501
502 See Also
503 --------
504 broadcast
505 broadcast_arrays
506 broadcast_shapes
507
508 Examples
509 --------
510 >>> import numpy as np
511 >>> x = np.array([1, 2, 3])
512 >>> np.broadcast_to(x, (3, 3))
513 array([[1, 2, 3],
514 [1, 2, 3],
515 [1, 2, 3]])
516 """
517 return _broadcast_to(array, shape, subok=subok, readonly=True)
518
519
520def _broadcast_shape(*args):

Callers 9

_count_reduce_itemsFunction · 0.90
tril_indicesFunction · 0.90
triu_indicesFunction · 0.90
test_broadcast_to_raisesFunction · 0.90
test_subclassesFunction · 0.90
test_writeableFunction · 0.90
test_reference_typesFunction · 0.90
_broadcast_shapeFunction · 0.85

Calls 1

_broadcast_toFunction · 0.85

Tested by 5

test_broadcast_to_raisesFunction · 0.72
test_subclassesFunction · 0.72
test_writeableFunction · 0.72
test_reference_typesFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…