Saturday, July 25, 2026
HomeLanguagesnumpy.sort_complex() in Python

numpy.sort_complex() in Python

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 :




# Python program explaining
# sort_complex() function
   
import numpy as geek
  
# input array
in_arr = [2, 8, 7, 5, 9]
print ("Input array : ", in_arr) 
    
out_arr = geek.sort_complex(in_arr) 
print ("Output sorted array : ", out_arr)


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 :




# Python program explaining
# sort_complex() function
   
import numpy as geek
  
# input array
in_arr = [2 + 4j, 5 + 9j, 3 - 2j, 4 - 3j, 3 + 5j, 2-4j, 5]
print ("Input array : ", in_arr)   
  
out_arr = geek.sort_complex(in_arr) 
print ("Output sorted array : ", out_arr)


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]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6972 POSTS0 COMMENTS