Pythonのnumpy.absolute()

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

パラメータ:

  arr:  [array_like]要素をテストする必要がある入力配列またはオブジェクト。 

戻り値:

各配列の絶対値を持つ配列。 

コード#1:作業


#説明するPythonプログラム
#absolute()関数


import numpy as np

arr1 = [ 1 - 3 15 - 466 ]

print "arr1の絶対値:"

np.absolute (arr1))

arr2 = [ 23 - 56 ]

print "絶対値of arr2: "

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

出力:

 arr1の絶対値:[1 3 15 466] arr2の絶対値:[23 56] 

コード#2:Workin複素数のg


#Pythonプログラムの説明
#absolute()関数


import numpy as np

a = 4 + 3j

印刷 "Absolute(4 + 3j):"

np.absolute (a))

b = 16 + 13j

print "絶対値(16 + 13j):"

np.absolute (b))

出力:

絶対値(4 + 3j):5.0絶対値(16 + 13j):20.6155281281 

コード# 3:numpy.absolute()のグラフィック表現


#説明するPythonプログラム
#absolute()function

import numpy as np

import matplotlib.pyplot as plt


a = np.linspace(start = - 5 、停止 = 5

num = 6 、エンドポイント = True


print "グラフィック表現:"

np.absolute < / a>(a))


plt.title( "blue:with Absolute赤:絶対なし "

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


plt.plot(a、a、color = `red`

plt.show()

出力:

グラフィック表現:[5。 3.1.1。 3. 5.] 

リンク:
https:/ /docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.absolute.html