MCPcopy
hub / github.com/numpy/numpy / sort_complex

Function sort_complex

numpy/lib/_function_base_impl.py:1871–1905  ·  view source on GitHub ↗

Sort a complex array using the real part first, then the imaginary part. Parameters ---------- a : array_like Input array Returns ------- out : complex ndarray Always returns a sorted complex array. Examples -------- >>> import numpy as np

(a)

Source from the content-addressed store, hash-verified

1869
1870@array_function_dispatch(_sort_complex)
1871def sort_complex(a):
1872 """
1873 Sort a complex array using the real part first, then the imaginary part.
1874
1875 Parameters
1876 ----------
1877 a : array_like
1878 Input array
1879
1880 Returns
1881 -------
1882 out : complex ndarray
1883 Always returns a sorted complex array.
1884
1885 Examples
1886 --------
1887 >>> import numpy as np
1888 >>> np.sort_complex([5, 3, 6, 2, 1])
1889 array([1.+0.j, 2.+0.j, 3.+0.j, 5.+0.j, 6.+0.j])
1890
1891 >>> np.sort_complex([1 + 2j, 2 - 1j, 3 - 2j, 3 - 3j, 3 + 5j])
1892 array([1.+2.j, 2.-1.j, 3.-3.j, 3.-2.j, 3.+5.j])
1893
1894 """
1895 b = array(a, copy=True)
1896 b.sort()
1897 if not issubclass(b.dtype.type, _nx.complexfloating):
1898 if b.dtype.char in 'bhBH':
1899 return b.astype('F')
1900 elif b.dtype.char == 'g':
1901 return b.astype('G')
1902 else:
1903 return b.astype('D')
1904 else:
1905 return b
1906
1907
1908def _arg_trim_zeros(filt):

Callers

nothing calls this directly

Calls 3

astypeMethod · 0.80
arrayFunction · 0.50
sortMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…