Returns a reshaped ndarray without changing data. Parameters ---------- a : array_like Array to be reshaped. shape : int or tuple of ints The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of th
(a, /, shape, order='C', *, copy=None)
| 206 | |
| 207 | @array_function_dispatch(_reshape_dispatcher) |
| 208 | def reshape(a, /, shape, order='C', *, copy=None): |
| 209 | """ |
| 210 | Returns a reshaped ndarray without changing data. |
| 211 | |
| 212 | Parameters |
| 213 | ---------- |
| 214 | a : array_like |
| 215 | Array to be reshaped. |
| 216 | shape : int or tuple of ints |
| 217 | The new shape should be compatible with the original shape. If |
| 218 | an integer, then the result will be a 1-D array of that length. |
| 219 | One shape dimension can be -1. In this case, the value is |
| 220 | inferred from the length of the array and remaining dimensions. |
| 221 | order : {'C', 'F', 'A'}, optional |
| 222 | Read the elements of ``a`` using this index order, and place the |
| 223 | elements into the reshaped array using this index order. 'C' |
| 224 | means to read / write the elements using C-like index order, |
| 225 | with the last axis index changing fastest, back to the first |
| 226 | axis index changing slowest. 'F' means to read / write the |
| 227 | elements using Fortran-like index order, with the first index |
| 228 | changing fastest, and the last index changing slowest. Note that |
| 229 | the 'C' and 'F' options take no account of the memory layout of |
| 230 | the underlying array, and only refer to the order of indexing. |
| 231 | 'A' means to read / write the elements in Fortran-like index |
| 232 | order if ``a`` is Fortran *contiguous* in memory, C-like order |
| 233 | otherwise. |
| 234 | copy : bool, optional |
| 235 | If ``True``, then the array data is copied. If ``None``, a copy will |
| 236 | only be made if it's required by ``order``. For ``False`` it raises |
| 237 | a ``ValueError`` if a copy cannot be avoided. Default: ``None``. |
| 238 | |
| 239 | Returns |
| 240 | ------- |
| 241 | reshaped_array : ndarray |
| 242 | This will be a new view object if possible; otherwise, it will |
| 243 | be a copy. Note there is no guarantee of the *memory layout* (C- or |
| 244 | Fortran- contiguous) of the returned array. |
| 245 | |
| 246 | See Also |
| 247 | -------- |
| 248 | ndarray.reshape : Equivalent method. |
| 249 | |
| 250 | Notes |
| 251 | ----- |
| 252 | It is not always possible to change the shape of an array without copying |
| 253 | the data. |
| 254 | |
| 255 | The ``order`` keyword gives the index ordering both for *fetching* |
| 256 | the values from ``a``, and then *placing* the values into the output |
| 257 | array. For example, let's say you have an array: |
| 258 | |
| 259 | >>> a = np.arange(6).reshape((3, 2)) |
| 260 | >>> a |
| 261 | array([[0, 1], |
| 262 | [2, 3], |
| 263 | [4, 5]]) |
| 264 | |
| 265 | You can think of reshaping as first raveling the array (using the given |
no test coverage detected
searching dependent graphs…