Trusted answers to developer questions

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.

The **sign()**** **function in NumPy is used to return the sign of each element (numbers) of an array.

numpy.sign(x, /, out=None, *, where=True)

The `sign()`

function takes the following parameter values:

**x****out****where**`True`

, the resulting array will be set to the`ufunc`

result. Otherwise, the resulting array will retain its original value. It is an optional parameter.****kwargs**

The `sign()`

function returns an array of the same shape as the input array passed to it, holding the sign of values of the elements of the input array.

`-1`

is returned if the number is less than `0`

. `1`

is returned for numbers greater than `0`

. `0`

is returned if the number is equal to `0`

. `NaN`

is returned if the input is a `NaN`

.

Let's look at the code below:

import numpy as np# creating an input array of complex valuesx = np.array([-1, 6, -2.5, 2])# implementing the sign() functionmyarray = np.sign(x)print(x)print(myarray)

Implementing the sign() function

- Line 1: We import the
`numpy`

module. - Line 4:
`x`

using the`array()`

function. - Line 7: We implement the
`sign()`

function on the input array. We assign the result to a variable`myarray`

. - Line 9: We print the variable
`x`

. - Line 10: We print the variable
`myarray`

.

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

Related Courses