How To Find Median In Python Using Numpy

The median is one of the most frequently used statistical measures. It is calculated by finding the middle value in a given data set.

Finding the median in Python can be quite easy if we use the powerful library numpy. In this tutorial, we will learn how to find the Median in Python using Numpy.


1. First, we need to install numpy in Python. We can do this using pip. Open the terminal and type the following command to install numpy.

2. After installing numpy, we need to import it into our Python code. Add the following line at the beginning of your code.

3. We will now create a numpy array with some random values. To do so, use the following code.

4. Next, we will use the numpy median() function to find the median of our array. Use the following code.

5. Finally, we will print the calculated median value using the print() function. Use the following code to print the median.


In this tutorial, you have learned how to find the Median in Python using numpy. Numpy is a powerful library that offers many functions to perform statistical calculations on your data. Try experimenting with different numpy functions to get familiar with them.


Median is: 4.0