We will create an array of complex numbers and sort it:
Generating random complex numbers : Generate five random numbers for the real part of the complex numbers and five numbers for the imaginary part. Seed the random generator to 42:
numpy.random.seed(42) complex_numbers = numpy.random.random(5) + 1j * numpy.random.random(5) print "Complex numbers\n", complex_numbers
Calling sort_complex on the random numbers: Call the
sort_complex
function to sort the complex numbers we generated in the previous step:print "Sorted\n", numpy.sort_complex(complex_numbers)
The sorted numbers would be:
Sorted[ 0.39342751+0.34955771j 0.40597665+0.77477433j 0.41516850+0.26221878j 0.86631422+0.74612422j 0.92293095+0.81335691j]