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.

## Steps

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.

1 |
pip 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.

1 |
import numpy as np |

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

1 |
arr = np.array([7, 2, 1, 6, 4, 5, 3]) |

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

1 |
median = np.median(arr) |

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

1 |
print("Median is:", median) |

## Conclusion

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.

1 2 3 4 5 6 7 8 9 10 |
import numpy as np # create array arr = np.array([7, 2, 1, 6, 4, 5, 3]) # find median median = np.median(arr) # print median print("Median is:", median) |

## Output:

Median is: 4.0