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)
| 1406 | |
| 1407 | @array_function_dispatch(_resize_dispatcher) |
| 1408 | def resize(a, new_shape): |
| 1409 | """ |
| 1410 | Return a new array with the specified shape. |
| 1411 | |
| 1412 | If the new array is larger than the original array, then the new |
| 1413 | array is filled with repeated copies of `a`. Note that this behavior |
| 1414 | is different from a.resize(new_shape) which fills with zeros instead |
| 1415 | of repeated copies of `a`. |
| 1416 | |
| 1417 | Parameters |
| 1418 | ---------- |
| 1419 | a : array_like |
| 1420 | Array to be resized. |
| 1421 | |
| 1422 | new_shape : int or tuple of int |
| 1423 | Shape of resized array. |
| 1424 | |
| 1425 | Returns |
| 1426 | ------- |
| 1427 | reshaped_array : ndarray |
| 1428 | The new array is formed from the data in the old array, repeated |
| 1429 | if necessary to fill out the required number of elements. The |
| 1430 | data are repeated iterating over the array in C-order. |
| 1431 | |
| 1432 | See Also |
| 1433 | -------- |
| 1434 | numpy.reshape : Reshape an array without changing the total size. |
| 1435 | numpy.pad : Enlarge and pad an array. |
| 1436 | numpy.repeat : Repeat elements of an array. |
| 1437 | ndarray.resize : resize an array in-place. |
| 1438 | |
| 1439 | Notes |
| 1440 | ----- |
| 1441 | When the total size of the array does not change `~numpy.reshape` should |
| 1442 | be used. In most other cases either indexing (to reduce the size) |
| 1443 | or padding (to increase the size) may be a more appropriate solution. |
| 1444 | |
| 1445 | Warning: This functionality does **not** consider axes separately, |
| 1446 | i.e. it does not apply interpolation/extrapolation. |
| 1447 | It fills the return array with the required number of elements, iterating |
| 1448 | over `a` in C-order, disregarding axes (and cycling back from the start if |
| 1449 | the new shape is larger). This functionality is therefore not suitable to |
| 1450 | resize images, or data where each axis represents a separate and distinct |
| 1451 | entity. |
| 1452 | |
| 1453 | Examples |
| 1454 | -------- |
| 1455 | >>> a=np.array([[0,1],[2,3]]) |
| 1456 | >>> np.resize(a,(2,3)) |
| 1457 | array([[0, 1, 2], |
| 1458 | [3, 0, 1]]) |
| 1459 | >>> np.resize(a,(1,4)) |
| 1460 | array([[0, 1, 2, 3]]) |
| 1461 | >>> np.resize(a,(2,4)) |
| 1462 | array([[0, 1, 2, 3], |
| 1463 | [0, 1, 2, 3]]) |
| 1464 | |
| 1465 | """ |
nothing calls this directly
no test coverage detected