Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Fivenum/Python/fivenum-1.py
Normal file
28
Task/Fivenum/Python/fivenum-1.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
from __future__ import division
|
||||
import math
|
||||
import sys
|
||||
|
||||
def fivenum(array):
|
||||
n = len(array)
|
||||
if n == 0:
|
||||
print("you entered an empty array.")
|
||||
sys.exit()
|
||||
x = sorted(array)
|
||||
|
||||
n4 = math.floor((n+3.0)/2.0)/2.0
|
||||
d = [1, n4, (n+1)/2, n+1-n4, n]
|
||||
sum_array = []
|
||||
|
||||
for e in range(5):
|
||||
floor = int(math.floor(d[e] - 1))
|
||||
ceil = int(math.ceil(d[e] - 1))
|
||||
sum_array.append(0.5 * (x[floor] + x[ceil]))
|
||||
|
||||
return sum_array
|
||||
|
||||
x = [0.14082834, 0.09748790, 1.73131507, 0.87636009, -1.95059594, 0.73438555, -0.03035726, 1.46675970,
|
||||
-0.74621349, -0.72588772, 0.63905160, 0.61501527, -0.98983780, -1.00447874, -0.62759469, 0.66206163,
|
||||
1.04312009, -0.10305385, 0.75775634, 0.32566578]
|
||||
|
||||
y = fivenum(x)
|
||||
print(y)
|
||||
2
Task/Fivenum/Python/fivenum-2.py
Normal file
2
Task/Fivenum/Python/fivenum-2.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import pandas as pd
|
||||
pd.DataFrame([1, 2, 3, 4, 5, 6]).describe()
|
||||
2
Task/Fivenum/Python/fivenum-3.py
Normal file
2
Task/Fivenum/Python/fivenum-3.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import pandas as pd
|
||||
pd.DataFrame([1, 2, 3, 4, 5, 6]).quantile([.0, .25, .50, .75, 1.00], interpolation='nearest')
|
||||
33
Task/Fivenum/Python/fivenum-4.py
Normal file
33
Task/Fivenum/Python/fivenum-4.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# fiveNums :: [Float] -> (Float, Float, Float, Float, Float)
|
||||
def fiveNums(xs):
|
||||
def median(xs):
|
||||
lng = len(xs)
|
||||
m = lng // 2
|
||||
return xs[m] if (
|
||||
0 != lng % 2
|
||||
) else (xs[m - 1] + xs[m]) / 2
|
||||
|
||||
ys = sorted(xs)
|
||||
lng = len(ys)
|
||||
m = lng // 2
|
||||
return (
|
||||
ys[0],
|
||||
median(ys[0:(m + (lng % 2))]),
|
||||
median(ys),
|
||||
median(ys[m:]),
|
||||
ys[-1]
|
||||
) if 0 < lng else None
|
||||
|
||||
|
||||
# TEST --------------------------------------------------------------------
|
||||
for xs in [[15, 6, 42, 41, 7, 36, 49, 40, 39, 47, 43],
|
||||
[36, 40, 7, 39, 41, 15],
|
||||
[
|
||||
0.14082834, 0.09748790, 1.73131507, 0.87636009, -1.95059594,
|
||||
0.73438555, -0.03035726, 1.46675970, -0.74621349, -0.72588772,
|
||||
0.63905160, 0.61501527, -0.98983780, -1.00447874, -0.62759469,
|
||||
0.66206163, 1.04312009, -0.10305385, 0.75775634, 0.32566578
|
||||
]]:
|
||||
print(
|
||||
fiveNums(xs)
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue