Python 中的 numpy.absolute()

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

`arr： [array_like] 輸入數組或對象的元素，我們需要測試。 `

`一個數組，每個數組的絕對值。 `

` # Python 程序解釋`
` # absolute() 函數`

` import ` ` numpy as np `

` `

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

` print ` ` (` ` "arr1 的絕對值：" ` `, `

` ` ` np.absolute (arr1)) `

` `

` arr2 ` ` = ` ` [` ` 23 ` `, ` ` - ` ` 56 ` `] `

` print ` ` (` `" 絕對值arr2: "` `, `

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

`arr1 的絕對值：[1 3 15 466] arr2 的絕對值：[23 56] `

 ` # Python程序解釋`` #絕對()函數` ` import ` ` numpy as np `` `` a ` ` = ` ` 4 ` ` + ` ` 3j `` print ` ` (` ` "絕對 (4 + 3j):" ` `, `` np.absolute (a)) ` ` b ` ` = ` ` 16 ` ` + ` `13j ``打印` `(` ` "絕對值 (16 + 13j):" ` `, `` np.absolute (b)) ` 輸出：`絕對值（4 + 3j）：5.0 絕對值（16 + 13j）：20.6155281281 ` 代碼# 3：numpy.absolute()的圖形表示 ` #Python程序解釋`` # absolute() 函數 ` ` import ` ` numpy as np `` import ` ` matplotlib.pyplot as plt ` ` 一個` ` = ` ` np.linspace (start ` ` = ` ` - ` ` 5 ` ` , 停止 ` ` = ` ` 5 ` `, `` num ` ` = ` `6` `,端點 ` ` = ` ` True ` `) `` print ` ` (` ` "圖形表示：" ` `, `` np.absolute< /a> (a)) `` plt.title (` ` "blue: 帶絕對紅色：沒有絕對的 "` `) `` plt.plot (a, a, color ` ` = ` ` `red` ` `) `` plt.show () ` 輸出：`圖形表示：[5. 3. 1. 1. 3. 5.] `