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.

In NumPy, the **absolute()**** function **is used to compute the

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

Syntax for the absolute() function in NumPy

This function takes the following parameter values:

: This represents an input array of values. This argument is mandatory.**x****out****:**This represents the location where the result is stored. This is optional.

: This is the condition over which the input is being broadcast. At a given location where this condition is**where**`True`

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

result. Otherwise, the resulting array will retain its original value. This is optional.

Note:`is short for universal function and it operates on ndarrays, in an element-wise fashion. It also supports other standard features in NumPy.`

ufunc

: This represents other keyword arguments. This is mandatory.****kwargs**

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

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

Implementing the absolute() function

- Line 1: We import the
`numpy`

module. - Line 4: We use the
`array()`

function to create an array`x`

. - Line 7: We call the
`absolute()`

function by passing the input array,`x`

as the argument. We assign the result to a variable`myarray`

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

. - Line 10: We print the new array
`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