NumPy Array Manipulation
NumPy Array Manipulation
1. reshape() Function:
This function takes two main arguments one is the array to reshape and the
other is tuple specifying the new shape. If the new shape is not compatible
with the total number of elements then a 'ValueError' is raised.
SYNTAX
numpy.reshape(arr, newshape)
Parameters
Example:
Note:
Or we can use (3,-1) ,Here -1 is for NumPy to decide about columns it will
depend upon your row value here , because total elements are 6 and we
have passed 3 there as rows so , the number of columns will be
automatically 2, similarly you can fix this Column and Put row as -1.
2. flatten() method:
This function is helpful when we need to rearrange array elements for data
transformation or analysis. It works for both 1D and multi-dimensional arrays.