本文整理匯總了Python中numpy.sort_complex方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.sort_complex方法的具體用法?Python numpy.sort_complex怎麽用?Python numpy.sort_complex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.sort_complex方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: sort_complex
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sort_complex [as 別名]
def sort_complex(a):
"""Sort a complex array using the real part first,
then the imaginary part.
Args:
a (cupy.ndarray): Array to be sorted.
Returns:
cupy.ndarray: sorted complex array.
.. seealso:: :func:`numpy.sort_complex`
"""
if a.dtype.char in 'bhBHF':
a = a.astype('F')
else:
a = a.astype('D')
a.sort()
return a
示例2: test_sort_real
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sort_complex [as 別名]
def test_sort_real(self, type_in, type_out):
# sort_complex() type casting for real input types
a = np.array([5, 3, 6, 2, 1], dtype=type_in)
actual = np.sort_complex(a)
expected = np.sort(a).astype(type_out)
assert_equal(actual, expected)
assert_equal(actual.dtype, expected.dtype)
示例3: test_sort_complex
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sort_complex [as 別名]
def test_sort_complex(self):
# sort_complex() handling of complex input
a = np.array([2 + 3j, 1 - 2j, 1 - 3j, 2 + 1j], dtype='D')
expected = np.array([1 - 3j, 1 - 2j, 2 + 1j, 2 + 3j], dtype='D')
actual = np.sort_complex(a)
assert_equal(actual, expected)
assert_equal(actual.dtype, expected.dtype)
示例4: sort_complex
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sort_complex [as 別名]
def sort_complex(a):
"""
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
--------
>>> np.sort_complex([5, 3, 6, 2, 1])
array([ 1.+0.j, 2.+0.j, 3.+0.j, 5.+0.j, 6.+0.j])
>>> np.sort_complex([1 + 2j, 2 - 1j, 3 - 2j, 3 - 3j, 3 + 5j])
array([ 1.+2.j, 2.-1.j, 3.-3.j, 3.-2.j, 3.+5.j])
"""
b = array(a, copy=True)
b.sort()
if not issubclass(b.dtype.type, _nx.complexfloating):
if b.dtype.char in 'bhBH':
return b.astype('F')
elif b.dtype.char == 'g':
return b.astype('G')
else:
return b.astype('D')
else:
return b
示例5: test_sort_complex
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import sort_complex [as 別名]
def test_sort_complex(self):
self.check(np.sort_complex)