VOOZH about

URL: https://www.geeksforgeeks.org/python/numpy-sort_complex-in-python/

⇱ numpy.sort_complex() in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

numpy.sort_complex() in Python

Last Updated : 24 Dec, 2018
numpy.sort_complex() function is used to sort a complex array.It sorts the array by using the real part first, then the imaginary part.
Syntax : numpy.sort_complex(arr) Parameters : arr : [array_like] Input array. Return : [complex ndarray] A sorted complex array.
Code #1 :
Output:
Input array : [2, 8, 7, 5, 9]
Output sorted array : [ 2.+0.j 5.+0.j 7.+0.j 8.+0.j 9.+0.j]
  Code #2 :
Output:
Input array : [(2+4j), (5+9j), (3-2j), (4-3j), (3+5j), (2-4j), 5]
Output sorted array : [ 2.-4.j 2.+4.j 3.-2.j 3.+5.j 4.-3.j 5.+0.j 5.+9.j]
Comment