Thanks to visit codestin.com
Credit goes to github.com

Skip to content

percentileofscore and multidimensional array #14421

@pmh722

Description

@pmh722

scipy.stats.percentileofscore seems to implicitly assume that input array "a" is a one dimensional vector. When it encounters a multidimensional matrix input, it seemingly calculates the percentile of each dimension, and SUMS them, resulting in a percentile that is potentially greater than 100?

This behaviors surprised me. I would have expected either 1) broadcasting (get back an array of percentiles), 2) reduction (get back the percentile as if the array were one dimensional), or 3) an error. My vote would be for (1), but any would be preferable to summing the percentiles.

Reproducing code example:

import numpy as np
from scipy import stats
foo = np.array([[1,2,3,4],[2,3,4,5]])
bar = stats.percentileofscore(foo, 2)
print(bar) #125

Scipy/Numpy/Python version information:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions