[Numpy-discussion] Getting 95%/99% margin of ndarray

Citi, Luca lciti@essex.ac...
Wed Jul 22 12:43:26 CDT 2009


I am afraid I misunderstand your question
because I do not get the results you expected.

def pdyn(a, p):
    a = np.sort(a)
    n = round((1-p) * len(a))
    return a[int((n+1)/2)], a[len(a)-1-int(n/2)] # a[-int(n/2)] would not work if n<=1

>>> pdyn([0, 0, 0, 0, 1, 2, 3, 4, 5, 2000], 1)
(0, 2000)
>>> pdyn([0, 0, 0, 0, 1, 2, 3, 4, 5, 2000], .9)
(0, 2000)
>>> pdyn([0, 0, 0, 0, 1, 2, 3, 4, 5, 2000], .5)
(0, 4)
>>> pdyn([0, 0, 0, 0, 1, 2, 3, 4, 5, 2000], .3)
(1, 3)

If you have the array
0 0 0 0 1 2 3 4 5 2000
why should 
p = 0.5 -> (1, 5)
?

I mean 10*.5 is 5, so you throw away 5 elements
from the upper and lower tail (either 3+2 or 2+3)
and you should end up with
either (0, 4) or (0, 3),
so why (1, 5) ?

Best,
Luca



More information about the NumPy-Discussion mailing list