top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Writer's pictureAbdelrhman Gaber

Median of sorted Array using python

in this application we pass to our function unsorted list and it will return the median of the list

steps:

1 - First we save the length of the list in a variable called length.

2 - use build in function in python called sort() to return the same list but sorted.

3 - check if we have odd number of elements or even number.

4 - if we have odd numbers the median will be in the middle of the list.

5 - if we have even numbers we take the two numbers in the middle and take the average value this value will be our middle for this list.

Here is the function that do that.


test our function for odd number of elements


test our function for even number of elements


conclusion

before we calculate the median we need first to sort our elements and then check if there is odd or even number of elements.


0 comments

Recent Posts

See All

COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page