Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
numpy
python
communitycreator

What is the numpy.sort_complex() function in NumPy?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The sort_complex() function in numpy is used to sort a given array by using the real and imaginary past. The real part comes first, and the imaginary part comes second.

Syntax

numpy.sort_complex(a)

Parameter value

The sort_complex() function takes a single parameter value, a, which represents the input array.

Return value

The sort_complex() function returns a sorted complex array.

import numpy as np
# creating an array
myarray = np.array([2, 4, 5, 3, 1])
# calling the numpy.sort_complex() function
complexarray = np.sort_complex(myarray)
print(complexarray)
Implementing the np.sort_complex() function

Explanation

  • Line 1: We import the numpy module.
  • Line 3: We create a 1D array, myarray, using the array() function.
  • Line 6: We implement the sort_complex() function on the array we created. The result is assigned to a new variable complexarray.
  • Line 8: We print the variable complexarray.

RELATED TAGS

function
numpy
python
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring