Skip to content

BUG: Quantile function on complex numbers doesn't error #22652

@aschaffer

Description

@aschaffer

Describe the issue:

Complex numbers are unordered. The complex set, ℂ, is isomorphic with ℝ², which is an unordered vector space. On the other hand, quantiles are the inverse of the cumulative distribution function, CDF. Which is monotonic. It must be, for its inverse to exist.

Consequentially, it makes no mathematical sense to apply quantiles to an unordered set, like a complex input array. Some order can be introduced (e.g., lexicographic) but it is artificial, without a sound mathematical support.

However, both sorting and quantiles functions work in numpy (see example below). Instead, an exception should be thrown.

Reproduce the code example:

import numpy as np

arr_c = np.array([0.5+3.0j, 2.1+0.5j, 1.6+2.3j], dtype=np.dtype('complex128'))
np.quantile(arr_c, 0.5)

Error message:

No response

NumPy/Python version information:

1.23.3 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:10)
[GCC 10.3.0]

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions