If you are looking to transform multi-dimensional Numpy array into a 1-Dimensional array then use Numpy `ravel()`

function. This function works similar to `flatten()`

function but there is one difference. The difference is that `ravel()`

function returns a view of array. If you try to change the value of any element present in the view, then that same change will be reflected in the original array.

np.ravel(array)

`array`

parameter is used to pass Numpy array that we want to flatten. It is a required parameter.

import numpy as np x = np.array([[23, 76, 11, 42], [74, 91, 8, 34]]) y = np.ravel(x) print('Flattened array: \n', y) y[1] = 121 print('Original array: \n', x)

Output of the above program

Flattened array: [23 76 11 42 74 91 8 34] Original array: [[ 23 121 11 42] [ 74 91 8 34]]

As you can see that we have changed the value of second element to 121 and that change is reflected in the original array `x`

.

- How to convert Numpy Array to List?
- What is NumPy ndarray shape in Python?
- What is NumPy axis?
- What are NumPy data types?
- What are structured arrays in Python NumPy?
- What are NumPy array attributes?
- How to iterate over NumPy array?
- What is NumPy arrays broadcasting?
- How to change data type of a given Numpy array?
- How to use NumPy split() in Python?
- How to use NumPy flatten() in Python?
- What is the difference between NumPy flatten() and ravel()?