October 2019
Beginner to intermediate
674 pages
16h 43m
English
The reshape function helps to modify the shape of the array. It accepts two main input arguments—the array to be processed and the expected shape as an integer or tuple of integers.
Previously in this chapter, we saw that np.arange should rely upon an external function to transform the data from being 1D:
In [78]: reshape_array = np.arange(0,15)In [79]: np.reshape(reshape_array, (5, 3))Out[79]:array([[ 0, 1, 2],[ 3, 4, 5],[ 6, 7, 8],[ 9, 10, 11],[12, 13, 14]]
The np.reshape function returns a view of the data, meaning the underlying array remains unchanged. In special cases, however, the shape cannot be changed without the data being copied. For more details on this, see the documentation at http://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html ...
Read now
Unlock full access