w3resource logo

:

Python Exercises

Python NumPy: Create a contiguous flattened array

Python NumPy: Array Object Exercise-36 with Solution

Write a Python program to create a contiguous flattened array.

Sample Solution:-

Python Code:

import numpy as np
x = np.array([[10, 20, 30], [20, 40, 50]])
print("Original array:")
print(x)
y = np.ravel(x)
print("New flattened array:")
print(y)

Sample Output:

Original array:                                                        
[[10 20 30]                                                            
 [20 40 50]]                                                           
New flattened array:                                                   
[10 20 30 20 40 50] 

Python Code Editor:

Improve this sample solution and post your code through Disqus