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