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)
| 366 | |
| 367 | @array_function_dispatch(_broadcast_to_dispatcher, module='numpy') |
| 368 | def broadcast_to(array, shape, subok=False): |
| 369 | """Broadcast an array to a new shape. |
| 370 | |
| 371 | Parameters |
| 372 | ---------- |
| 373 | array : array_like |
| 374 | The array to broadcast. |
| 375 | shape : tuple or int |
| 376 | The shape of the desired array. A single integer ``i`` is interpreted |
| 377 | as ``(i,)``. |
| 378 | subok : bool, optional |
| 379 | If True, then sub-classes will be passed-through, otherwise |
| 380 | the returned array will be forced to be a base-class array (default). |
| 381 | |
| 382 | Returns |
| 383 | ------- |
| 384 | broadcast : array |
| 385 | A readonly view on the original array with the given shape. It is |
| 386 | typically not contiguous. Furthermore, more than one element of a |
| 387 | broadcasted array may refer to a single memory location. |
| 388 | |
| 389 | Raises |
| 390 | ------ |
| 391 | ValueError |
| 392 | If the array is not compatible with the new shape according to NumPy's |
| 393 | broadcasting rules. |
| 394 | |
| 395 | See Also |
| 396 | -------- |
| 397 | broadcast |
| 398 | broadcast_arrays |
| 399 | broadcast_shapes |
| 400 | |
| 401 | Notes |
| 402 | ----- |
| 403 | .. versionadded:: 1.10.0 |
| 404 | |
| 405 | Examples |
| 406 | -------- |
| 407 | >>> x = np.array([1, 2, 3]) |
| 408 | >>> np.broadcast_to(x, (3, 3)) |
| 409 | array([[1, 2, 3], |
| 410 | [1, 2, 3], |
| 411 | [1, 2, 3]]) |
| 412 | """ |
| 413 | return _broadcast_to(array, shape, subok=subok, readonly=True) |
| 414 | |
| 415 | |
| 416 | def _broadcast_shape(*args): |