Repeat each element of an array after themselves Parameters ---------- a : array_like Input array. repeats : int or array of ints The number of repetitions for each element. `repeats` is broadcasted to fit the shape of the given axis. axis : int, op
(a, repeats, axis=None)
| 422 | |
| 423 | @array_function_dispatch(_repeat_dispatcher) |
| 424 | def repeat(a, repeats, axis=None): |
| 425 | """ |
| 426 | Repeat each element of an array after themselves |
| 427 | |
| 428 | Parameters |
| 429 | ---------- |
| 430 | a : array_like |
| 431 | Input array. |
| 432 | repeats : int or array of ints |
| 433 | The number of repetitions for each element. `repeats` is broadcasted |
| 434 | to fit the shape of the given axis. |
| 435 | axis : int, optional |
| 436 | The axis along which to repeat values. By default, use the |
| 437 | flattened input array, and return a flat output array. |
| 438 | |
| 439 | Returns |
| 440 | ------- |
| 441 | repeated_array : ndarray |
| 442 | Output array which has the same shape as `a`, except along |
| 443 | the given axis. |
| 444 | |
| 445 | See Also |
| 446 | -------- |
| 447 | tile : Tile an array. |
| 448 | unique : Find the unique elements of an array. |
| 449 | |
| 450 | Examples |
| 451 | -------- |
| 452 | >>> np.repeat(3, 4) |
| 453 | array([3, 3, 3, 3]) |
| 454 | >>> x = np.array([[1,2],[3,4]]) |
| 455 | >>> np.repeat(x, 2) |
| 456 | array([1, 1, 2, 2, 3, 3, 4, 4]) |
| 457 | >>> np.repeat(x, 3, axis=1) |
| 458 | array([[1, 1, 1, 2, 2, 2], |
| 459 | [3, 3, 3, 4, 4, 4]]) |
| 460 | >>> np.repeat(x, [1, 2], axis=0) |
| 461 | array([[1, 2], |
| 462 | [3, 4], |
| 463 | [3, 4]]) |
| 464 | |
| 465 | """ |
| 466 | return _wrapfunc(a, 'repeat', repeats, axis=axis) |
| 467 | |
| 468 | |
| 469 | def _put_dispatcher(a, ind, v, mode=None): |