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)
| 473 | |
| 474 | @array_function_dispatch(_broadcast_to_dispatcher, module='numpy') |
| 475 | def 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 | |
| 520 | def _broadcast_shape(*args): |
searching dependent graphs…