Compute the median of the flattened NumPy array Last Updated : 05 Sep, 2020 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to compute the median of the flattened array. Median is basically that value that separates the lower half of the array with the higher half of array. Example: If there are odd numbers in an array. A = [1,2,3,4,5,6,7] Then the median element will be 7+1/2= 4th element of the array. Hence the Median in this array is 4. If there are even numbers in an array A = [1,2,3,4,5,6,7,8] Then the median element will be average of two middle elements. Here it will be an average of 4th and 5th element of the array that is 4+1/2 =4.5. It can be calculated using the numpy.median() function in Python. This function computes the median of the given data (array elements) along the specified axis. Syntax: numpy.median(arr, axis = None) Example 1: Odd no of elements Python3 # importing numpy as library import numpy as np # creating 1 D array with odd no of # elements x_odd = np.array([1, 2, 3, 4, 5, 6, 7]) print("\nPrinting the Original array:") print(x_odd) # calculating median med_odd = np.median(x_odd) print("\nMedian of the array that contains \ odd no of elements:") print(med_odd) Output: Printing the Original array: [1 2 3 4 5 6 7] Median of the array that contains odd no of elements: 4.0 Example 2: Even no of elements: Python3 # importing numpy as library import numpy as np # creating 1 D array with even no of # elements x_even = np.array([1, 2, 3, 4, 5, 6, 7, 8]) print("\nPrinting the Original array:") print(x_even) # calculating median med_even = np.median(x_even) print("\nMedian of the array that contains \ even no of elements:") print(med_even) Output: Printing the Original array: [1 2 3 4 5 6 7 8] Median of the array that contains even no of elements: 4.5 Comment More infoAdvertise with us Next Article Compute the median of the flattened NumPy array H hupphurr Follow Improve Article Tags : Python Python-numpy Python numpy-Statistics Functions Practice Tags : python Similar Reads Create a contiguous flattened NumPy array 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 : Inpu 2 min read Flatten Specific Dimensions of NumPy Array A general-purpose array-processing package that is used for working with arrays is called NumPy. Do you want to collapse your Numpy array into one dimension? If yes, then you can do so by flattening your Numpy array. In this article, we will see how we can flatten only some dimensions of a Numpy arr 2 min read NumPy| How to get the unique elements of an Array To find unique elements of an array we use the numpy.unique() method of the NumPy library in Python. It returns unique elements in a new sorted array. Example: Python3 import numpy as np arr = np.array([1, 2, 3, 1, 4, 5, 2, 5]) unique_elements = np.unique(arr) print(unique_elements) Output: [1 2 3 4 2 min read How to calculate the element-wise absolute value of NumPy array? Let's see the program for finding the element-wise absolute value of NumPy array. For doing this task we are using numpy.absolute() function of NumPy library. This mathematical function helps to calculate the absolute value of each element in the array. Syntax: numpy.absolute(arr, out = None, ufunc 2 min read How to round elements of the NumPy array to the nearest integer? Prerequisites: Python NumPy In this article, let's discuss how to round elements of the NumPy array to the nearest integer. numpy.rint() function of Python that can convert the elements of an array to the nearest integer. Syntax: numpy.rint(x, /, out=None, *, where=True, casting='same_kind', order=' 1 min read Like