Array API compatible wrapper for :py:func:`np.reshape `. See its docstring for more information.
(x: Array,
/,
shape: Tuple[int, ...],
*,
copy: Optional[Bool] = None)
| 54 | |
| 55 | # Note: the optional argument is called 'shape', not 'newshape' |
| 56 | def reshape(x: Array, |
| 57 | /, |
| 58 | shape: Tuple[int, ...], |
| 59 | *, |
| 60 | copy: Optional[Bool] = None) -> Array: |
| 61 | """ |
| 62 | Array API compatible wrapper for :py:func:`np.reshape <numpy.reshape>`. |
| 63 | |
| 64 | See its docstring for more information. |
| 65 | """ |
| 66 | |
| 67 | data = x._array |
| 68 | if copy: |
| 69 | data = np.copy(data) |
| 70 | |
| 71 | reshaped = np.reshape(data, shape) |
| 72 | |
| 73 | if copy is False and not np.shares_memory(data, reshaped): |
| 74 | raise AttributeError("Incompatible shape for in-place modification.") |
| 75 | |
| 76 | return Array._new(reshaped) |
| 77 | |
| 78 | |
| 79 | def roll( |