Skip to content

bug in percentile Linear #10373

@jhelie

Description

@jhelie
>>>  np.__version__
'1.13.3'

A rounding error occurs for certain value/percentile combinations.

>>> a = np.ones(279) * 0.56758051638767337
>>> np.unique(a)
array([ 0.56758052])

The array containing only identical values all percentiles should be equal to that value but that is not the case for the 45th percentile:

>>> for p in range(0,100,5):
        if np.percentile(a, p) != a[0]:
            print(p)
45

And indeed:

>>> np.percentile(a, 45)
0.56758051638767348
>>> np.percentile(a, 45) - a[0]
1.1102230246251565e-16

The problematic percentile(s) depend on the length and the value of the array:

>>> b = np.ones(279) * 60287681548494698
>>> np.unique(b)
array([ 60287682])
>>> for p in range(0,100,5):
        if np.percentile(b, p) != b[0]:
            print(p)
95
>>> np.percentile(b, 95)
0.60287681548494709

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions