numpy.absolute () in Python

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

Parameter:

arr:  [array_like] Eingabe-Array oder Objekt, dessen Elemente wir testen müssen. 

Rückgabe:

Ein Array mit dem absoluten Wert jedes Arrays. 

Code # 1: Arbeit


# Python-Programm erklärt
# absolute () Funktion


import numpy as np

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

print ( "Absoluter Wert von arr1:" ,

np.absolute (arr1))

arr2 = [ 23 , - 56 ]

print ( " Absoluter Wert von arr2: " ,

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

Ausgabe:

Absoluter Wert von arr1: [1 3 15 466] Absoluter Wert von arr2: [23 56] 

Code # 2: Arbeiten g mit komplexen Zahlen


# Python-Programm erklärt
# absolute ()-Funktion


import numpy as np

a = 4 + 3j

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

np.absolute (a))

b = 16 + 13j

print ( "Absolutwert (16 + 13j):" ,

np.absolute (b))

Ausgabe:

Absolut (4 + 3j): 5,0 Absolutwert ( 16 + 13j): 20,6155281281 

Code # 3: Grafische Darstellung von numpy.absolute ()


# Python-Programm, das die
# absolute () function

import numpy as np

import matplotlib.pyplot as plt


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

num = 6 , Endpunkt = True )


print ( "Graphical Representation:" ,

np.absolute< /a> (a))


plt.title ( "blue: with absolute rot: ohne absolutes " )

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


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

plt.show ()

Ausgabe:

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

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