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-cl
(*args, subok=False)
| 479 | |
| 480 | @array_function_dispatch(_broadcast_arrays_dispatcher, module='numpy') |
| 481 | def broadcast_arrays(*args, subok=False): |
| 482 | """ |
| 483 | Broadcast any number of arrays against each other. |
| 484 | |
| 485 | Parameters |
| 486 | ---------- |
| 487 | `*args` : array_likes |
| 488 | The arrays to broadcast. |
| 489 | |
| 490 | subok : bool, optional |
| 491 | If True, then sub-classes will be passed-through, otherwise |
| 492 | the returned arrays will be forced to be a base-class array (default). |
| 493 | |
| 494 | Returns |
| 495 | ------- |
| 496 | broadcasted : list of arrays |
| 497 | These arrays are views on the original arrays. They are typically |
| 498 | not contiguous. Furthermore, more than one element of a |
| 499 | broadcasted array may refer to a single memory location. If you need |
| 500 | to write to the arrays, make copies first. While you can set the |
| 501 | ``writable`` flag True, writing to a single output value may end up |
| 502 | changing more than one location in the output array. |
| 503 | |
| 504 | .. deprecated:: 1.17 |
| 505 | The output is currently marked so that if written to, a deprecation |
| 506 | warning will be emitted. A future version will set the |
| 507 | ``writable`` flag False so writing to it will raise an error. |
| 508 | |
| 509 | See Also |
| 510 | -------- |
| 511 | broadcast |
| 512 | broadcast_to |
| 513 | broadcast_shapes |
| 514 | |
| 515 | Examples |
| 516 | -------- |
| 517 | >>> x = np.array([[1,2,3]]) |
| 518 | >>> y = np.array([[4],[5]]) |
| 519 | >>> np.broadcast_arrays(x, y) |
| 520 | [array([[1, 2, 3], |
| 521 | [1, 2, 3]]), array([[4, 4, 4], |
| 522 | [5, 5, 5]])] |
| 523 | |
| 524 | Here is a useful idiom for getting contiguous copies instead of |
| 525 | non-contiguous views. |
| 526 | |
| 527 | >>> [np.array(a) for a in np.broadcast_arrays(x, y)] |
| 528 | [array([[1, 2, 3], |
| 529 | [1, 2, 3]]), array([[4, 4, 4], |
| 530 | [5, 5, 5]])] |
| 531 | |
| 532 | """ |
| 533 | # nditer is not used here to avoid the limit of 32 arrays. |
| 534 | # Otherwise, something like the following one-liner would suffice: |
| 535 | # return np.nditer(args, flags=['multi_index', 'zerosize_ok'], |
| 536 | # order='C').itviews |
| 537 | |
| 538 | args = [np.array(_m, copy=False, subok=subok) for _m in args] |