Python Numpy.log() - 自然對數
Jinku Hu
2023年1月30日
2020年6月17日
numpy.log()
函式計算給定陣列中每個元素的自然對數。
numpy.log()
語法
numpy.log(arr)
引數
arr |
輸入陣列 |
返回值
它返回輸入陣列中每個元素的自然對數。
示例程式碼:numpy.log()
import numpy as np
arr = [1, np.e, np.e**2, np.e**3]
print(np.log(arr))
輸出:
[0. 1. 2. 3.]
示例程式碼: numpy.log2()
- 基數為 2 的對數
numpy.log2()
與 numpy.log()
類似,但基數是 2 而不是 e
。
import numpy as np
arr = [1, 2, np.e, 4]
print(np.log2(arr))
輸出:
[0. 1. 1.44269504 2.]
示例程式碼: numpy.log10()
- 對數基數為 10
numpy.log10()
類似於 numpy.log()
,但基數是 10 而不是 e
。
import numpy as np
arr = [1, np.e, 10, 100]
print(np.log10(arr))
輸出:
[0. 0.43429448 1. 2.]
Author: Jinku Hu
Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.
LinkedIn