Create a contiguous flattened NumPy array Last Updated : 19 Aug, 2020 Improve Improve Like Article Like Save Share Report Let us see how to create a contiguous array in NumPy.The contiguous flattened array is a two-dimensional and multi-dimensional array that is stored as a one-dimensional array. We will be using the ravel() method to perform this task. Syntax : numpy.ravel(array, order = ‘C’) Parameters : array : Input array. order : C-contiguous, F-contiguous, A-contiguous; optional Returns : Flattened array having same type as the Input array and and order as per choice. Example 1 : Flattening a 2D array. Python3 # Importing libraries import numpy as np # Creating 2D array arr = np.array([[5, 6, 7], [8, 9, 10]]) print("Original array:\n", arr) # Flattening the array flattened_array = np.ravel(arr) print("New flattened array:\n", flattened_array) Output : Original array: [[ 5 6 7] [ 8 9 10]] New flattened array: [ 5 6 7 8 9 10] Example 2 : Flattening a 3D array. Python3 # Importing libraries import numpy as np # Creating 3D array arr = np.array([[[3, 4], [5, 6]], [[7, 8], [9, 0]]]) print("Original array:\n", arr) # Flattening the array flattened_array = np.ravel(arr) print("New flattened array:\n", flattened_array) Output : Original array: [[[3 4] [5 6]] [[7 8] [9 0]]] New flattened array: [3 4 5 6 7 8 9 0] Like Article Suggest improvement Next Flatten A list of NumPy arrays Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads Compute the median of the flattened NumPy array Python | Convert flattened dictionary into nested dictionary Python | Convert nested dictionary into flattened dictionary PyCairo - How we can copy flattened path? Why does a nested loop perform much faster than the flattened one? NumPy Array Sorting | How to sort NumPy Array Difference between Numpy array and Numpy matrix NumPy ndarray.tolist() Method | Convert NumPy Array to List NumPy ndarray.size() Method | Get Number of Elements in NumPy Array NumPy ndarray.__abs__() | Find Absolute Value of Elements in NumPy Array Like G gerralife Follow Article Tags : Python numpy-arrayManipulation Python-numpy Python Practice Tags : python