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

Function broadcast_arrays

numpy/lib/_stride_tricks_impl.py:589–656  ·  view source on GitHub ↗

Broadcast any number of arrays against each other. Parameters ---------- *args : array_likes The arrays to broadcast. subok : bool, optional If True, then sub-classes will be passed-through, otherwise the returned arrays will be forced to be a base-clas

(*args, subok=False)

Source from the content-addressed store, hash-verified

587
588@array_function_dispatch(_broadcast_arrays_dispatcher, module='numpy')
589def broadcast_arrays(*args, subok=False):
590 """
591 Broadcast any number of arrays against each other.
592
593 Parameters
594 ----------
595 *args : array_likes
596 The arrays to broadcast.
597
598 subok : bool, optional
599 If True, then sub-classes will be passed-through, otherwise
600 the returned arrays will be forced to be a base-class array (default).
601
602 Returns
603 -------
604 broadcasted : tuple of arrays
605 These arrays are views on the original arrays. They are typically
606 not contiguous. Furthermore, more than one element of a
607 broadcasted array may refer to a single memory location. If you need
608 to write to the arrays, make copies first. While you can set the
609 ``writable`` flag True, writing to a single output value may end up
610 changing more than one location in the output array.
611
612 .. deprecated:: 1.17
613 The output is currently marked so that if written to, a deprecation
614 warning will be emitted. A future version will set the
615 ``writable`` flag False so writing to it will raise an error.
616
617 See Also
618 --------
619 broadcast
620 broadcast_to
621 broadcast_shapes
622
623 Examples
624 --------
625 >>> import numpy as np
626 >>> x = np.array([[1,2,3]])
627 >>> y = np.array([[4],[5]])
628 >>> np.broadcast_arrays(x, y)
629 (array([[1, 2, 3],
630 [1, 2, 3]]),
631 array([[4, 4, 4],
632 [5, 5, 5]]))
633
634 Here is a useful idiom for getting contiguous copies instead of
635 non-contiguous views.
636
637 >>> [np.array(a) for a in np.broadcast_arrays(x, y)]
638 [array([[1, 2, 3],
639 [1, 2, 3]]),
640 array([[4, 4, 4],
641 [5, 5, 5]])]
642
643 """
644 # nditer is not used here to avoid the limit of 64 arrays.
645 # Otherwise, something like the following one-liner would suffice:
646 # return np.nditer(args, flags=['multi_index', 'zerosize_ok'],

Callers 9

assert_shapes_correctFunction · 0.90
assert_same_as_ufuncFunction · 0.90
test_sameFunction · 0.90
test_broadcast_kwargsFunction · 0.90
test_one_offFunction · 0.90
test_subclassesFunction · 0.90
test_writeableFunction · 0.90
test_reference_typesFunction · 0.90

Calls 2

_broadcast_shapeFunction · 0.85
_broadcast_toFunction · 0.85

Tested by 9

assert_shapes_correctFunction · 0.72
assert_same_as_ufuncFunction · 0.72
test_sameFunction · 0.72
test_broadcast_kwargsFunction · 0.72
test_one_offFunction · 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…