python convert multidimensional array to one dimensional

In [12]: a = np.array([[1,2,3], [4,5,6]])

In [13]: b = a.ravel()

In [14]: b
Out[14]: array([1, 2, 3, 4, 5, 6])

Here is what the above code is Doing:
1. We create a 2D array with 2 rows and 3 columns.
2. We use the ravel() method to flatten the 2D array into a 1D array.
3. We print the 1D array.

The ravel() method returns a view of the original array whenever possible. This means that modifying the array returned by ravel() will modify the entries in the original array. If we modify the flattened array, the changes will be reflected in the original array:

In [15]: b[0] = 100

In [16]: b
Out[16]: array([100, 2, 3, 4, 5, 6])

In [17]: a
Out[17]: array([[100, 2, 3],
[ 4, 5, 6]])