Return a new array with the specified shape. If the new array is larger than the original array, then the new array is filled with repeated copies of `a`. Note that this behavior is different from a.resize(new_shape) which fills with zeros instead of repeated copies of `a`.
(a, new_shape)
| 1545 | |
| 1546 | @array_function_dispatch(_resize_dispatcher) |
| 1547 | def resize(a, new_shape): |
| 1548 | """ |
| 1549 | Return a new array with the specified shape. |
| 1550 | |
| 1551 | If the new array is larger than the original array, then the new |
| 1552 | array is filled with repeated copies of `a`. Note that this behavior |
| 1553 | is different from a.resize(new_shape) which fills with zeros instead |
| 1554 | of repeated copies of `a`. |
| 1555 | |
| 1556 | Parameters |
| 1557 | ---------- |
| 1558 | a : array_like |
| 1559 | Array to be resized. |
| 1560 | |
| 1561 | new_shape : int or tuple of int |
| 1562 | Shape of resized array. |
| 1563 | |
| 1564 | Returns |
| 1565 | ------- |
| 1566 | reshaped_array : ndarray |
| 1567 | The new array is formed from the data in the old array, repeated |
| 1568 | if necessary to fill out the required number of elements. The |
| 1569 | data are repeated iterating over the array in C-order. |
| 1570 | |
| 1571 | See Also |
| 1572 | -------- |
| 1573 | numpy.reshape : Reshape an array without changing the total size. |
| 1574 | numpy.pad : Enlarge and pad an array. |
| 1575 | numpy.repeat : Repeat elements of an array. |
| 1576 | ndarray.resize : resize an array in-place. |
| 1577 | |
| 1578 | Notes |
| 1579 | ----- |
| 1580 | When the total size of the array does not change `~numpy.reshape` should |
| 1581 | be used. In most other cases either indexing (to reduce the size) |
| 1582 | or padding (to increase the size) may be a more appropriate solution. |
| 1583 | |
| 1584 | Warning: This functionality does **not** consider axes separately, |
| 1585 | i.e. it does not apply interpolation/extrapolation. |
| 1586 | It fills the return array with the required number of elements, iterating |
| 1587 | over `a` in C-order, disregarding axes (and cycling back from the start if |
| 1588 | the new shape is larger). This functionality is therefore not suitable to |
| 1589 | resize images, or data where each axis represents a separate and distinct |
| 1590 | entity. |
| 1591 | |
| 1592 | Examples |
| 1593 | -------- |
| 1594 | >>> import numpy as np |
| 1595 | >>> a = np.array([[0,1],[2,3]]) |
| 1596 | >>> np.resize(a,(2,3)) |
| 1597 | array([[0, 1, 2], |
| 1598 | [3, 0, 1]]) |
| 1599 | >>> np.resize(a,(1,4)) |
| 1600 | array([[0, 1, 2, 3]]) |
| 1601 | >>> np.resize(a,(2,4)) |
| 1602 | array([[0, 1, 2, 3], |
| 1603 | [0, 1, 2, 3]]) |
| 1604 |
nothing calls this directly
no test coverage detected
searching dependent graphs…