Repository: scipy/scipy

Issue:
BUG: scipy.stats.percentileofscore has a mistake
### Describe your issue.

These are the first two lines in the function `scipy.stats.percentileofscore`
```
    a = np.asarray(a)
    n = len(a)
```
I think second line is wrong and it should be instead 
```
    a = np.asarray(a)
    n = a.shape[-1]
```
as later in the function we aggregate over the `axis=-1` using `np.count_nonzero`

### Reproducing Code Example

```python
import numpy as np
from scipy.stats import percentileofscore


a = np.zeros((6, 1000))
perc = percentileofscore(a, 1)

print(perc)

# Gives `[16666.66666667 16666.66666667 16666.66666667 16666.66666667 16666.66666667 16666.66666667]`
# All values are above 100; not percentile
```


### Error message

```shell
No error
```


### SciPy/NumPy/Python version and system information

```shell
1.11.2 1.26.0 sys.version_info(major=3, minor=11, micro=6, releaselevel='final', serial=0)

{
  "Compilers": {
    "c": {
      "name": "gcc",
      "linker": "ld.bfd",
      "version": "10.2.1",
      "commands": "cc"
    },
    "cython": {
      "name": "cython",
      "linker": "cython",
      "version": "0.29.36",
      "commands": "cython"
    },
    "c++": {
      "name": "gcc",
      "linker": "ld.bfd",
      "version": "10.2.1",
      "commands": "c++"
    },
    "fortran": {
      "name": "gcc",
      "linker": "ld.bfd",
      "version": "10.2.1",
      "commands": "gfortran"
    },
    "pythran": {
      "version": "0.13.1",
      "include directory": "../../tmp/pip-build-env-tshsyzfz/overlay/lib/python3.11/site-packages/pythran"
    }
  },
  "Machine Information": {
    "host": {
      "cpu": "x86_64",
      "family": "x86_64",
      "endian": "little",
      "system": "linux"
    },
    "build": {
      "cpu": "x86_64",
      "family": "x86_64",
      "endian": "little",
      "system": "linux"
    },
    "cross-compiled": false
  },
  "Build Dependencies": {
    "blas": {
      "name": "openblas",
      "found": true,
      "version": "0.3.21.dev",
      "detection method": "pkgconfig",
      "include directory": "/usr/local/include",
      "lib directory": "/usr/local/lib",
      "openblas configuration": "USE_64BITINT= DYNAMIC_ARCH=1 DYNAMIC_OLDER= NO_CBLAS= NO_LAPACK= NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP= HASWELL MAX_THREADS=2",
      "pc file directory": "/usr/local/lib/pkgconfig"
    },
    "lapack": {
      "name": "openblas",
      "found": true,
      "version": "0.3.21.dev",
      "detection method": "pkgconfig",
      "include directory": "/usr/local/include",
      "lib directory": "/usr/local/lib",
      "openblas configuration": "USE_64BITINT= DYNAMIC_ARCH=1 DYNAMIC_OLDER= NO_CBLAS= NO_LAPACK= NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP= HASWELL MAX_THREADS=2",
      "pc file directory": "/usr/local/lib/pkgconfig"
    },
    "pybind11": {
      "name": "pybind11",
      "version": "2.10.4",
      "detection method": "config-tool",
      "include directory": "unknown"
    }
  },
  "Python Information": {
    "path": "/opt/python/cp311-cp311/bin/python",
    "version": "3.11"
  }
```



Discussion:
`percentileofscore` doesn't appear to be intended to work n-dimensional `a` as written. If it were, it would need to accept an `axis` argument. (Surprisingly, it is supposed to accept n-d `scores`, but I can't say much about that.) I think a documentation fix stating that `a` must be 1D would be acceptable for now. Someone could propose an anhancement to make it work with n-dimensional `a`, but I'd suggest lining up a reviewer before getting started.

Resolving patch:
diff --git a/scipy/stats/_stats_py.py b/scipy/stats/_stats_py.py
--- a/scipy/stats/_stats_py.py
+++ b/scipy/stats/_stats_py.py
@@ -2260,7 +2260,7 @@ def percentileofscore(a, score, kind='rank', nan_policy='propagate'):
     Parameters
     ----------
     a : array_like
-        Array to which `score` is compared.
+        A 1-D array to which `score` is compared.
     score : array_like
         Scores to compute percentiles for.
     kind : {'rank', 'weak', 'strict', 'mean'}, optional


Test patch: