(→Python) |
|||
1번째 줄: | 1번째 줄: | ||
[[category: Math]] | [[category: Math]] | ||
==Excel== | |||
[[category: Excel]] | |||
<source lang='php'> | |||
=MEDIAN(11, 1, 2, 12) | |||
// 6.5 | |||
=MEDIAN(11, 1, 2) | |||
// 2 | |||
</source> | |||
==Python== | ==Python== |
2014년 5월 31일 (토) 22:07 판
1 Excel
PHP
Copy
=MEDIAN(11, 1, 2, 12)
// 6.5
=MEDIAN(11, 1, 2)
// 2
2 Python
Python
Copy
def median(lst):
lst_len = len(lst)
lst = sorted(lst)
if lst_len % 2 == 0:
return (lst[lst_len/2-1]+lst[lst_len/2])/2.0
return lst[lst_len/2]
print median([11, 1, 2, 12])
# 6.5
print median([11, 1, 12])
# 11
3 같이 보기
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.