numpy.absolute() in Python

| | | | | | | | | | | | | | | |

Parameters:

arr:  [array_like] Voer een array of object in waarvan we de elementen moeten testen. 

Return:

Een array met absolute waarde van elke array. 

Code #1: Werk


# Python-programma met uitleg
# absolute () functie


import numpy as np

arr1 = [ 1 , - 3 , 15 , - 466 ]

print ( "Absolute waarde van arr1:" ,

np.absolute (arr1))

arr2 = [ 23 , - 56 ]

print ( " Absolute waarde van arr2: " ,

< a href="https://python.engineering/numpy-absolute-python/">np.absolute (arr2))

Uitvoer:

Absolute waarde van arr1: [1 3 15 466] Absolute waarde van arr2: [23 56] 

Code #2: Aan het werk g met complexe getallen


# Python-programma uitgelegd
# absolute () functie


import numpy as np

a = 4 + 3j

print ( "Absoluut (4 + 3j):" ,

np.absolute (a))

b = 16 + 13j

print ( "Absolute waarde (16 + 13j):" ,

np.absolute (b))

Uitvoer:

Absoluut (4 + 3j): 5,0 Absolute waarde ( 16 + 13j): 20.6155281281 

Code # 3: Grafische weergave van numpy.absolute ()


# Python-programma met uitleg
# absolute () functie

import numpy as np

import matplotlib.pyplot als plt


a = np.linspace (start = - 5 , stop = 5 ,

num = 6 , eindpunt = True )


print ( "Grafische weergave:" ,

np.absolute< /a> (a))


plt.title ( "blauw: met absoluut rood: zonder absoluut " )

plt.plot (a, < a href="https://python.engineering/numpy-absolute-python/">np.absolute (a) )


plt.plot (a, a, color = `red` )

plt.show ()

Uitvoer:

Grafische weergave: [5. 3. 1. 1 . 3. 5.] 

Links:
https: / /docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.absolute.html
,