numpy.log() 用法及代码示例
numpy.log(x [,out] = ufunc’log1p’): 此数学函数可帮助用户计算x的自然对数,其中x属于所有输入数组元素。
自然对数对数是exp()的逆, 以便log(exp(x))= x。自然对数是以e为底的对数。
参数:
array : [数组]输入数组或对象。
out : [ndarray,可选]输出数组,其尺寸与输入数组相同,并放置在结果中。
返回:
自然对数值为x的数组;其中x属于输入数组的所有元素。
代码1:工作
# Python program explaining
# log() function
import numpy as np
in_array = [1, 3, 5, 2**8]
print ("Input array : ", in_array)
out_array = np.log(in_array)
print ("Output array : ", out_array)
print("\nnp.log(4**4) : ", np.log(4**4))
print("np.log(2**8) : ", np.log(2**8))
输出:
Input array : [1, 3, 5, 256] Output array : [ 0. 1.09861229 1.60943791 5.54517744] np.log(4**4) : 5.54517744448 np.log(2**8) : 5.54517744448
代码2:图形表示
# Python program showing
# Graphical representation
# of log() function
import numpy as np
import matplotlib.pyplot as plt
in_array = [1, 1.2, 1.4, 1.6, 1.8, 2]
out_array = np.log(in_array)
print ("out_array : ", out_array)
plt.plot(in_array, in_array,
color = 'blue', marker = "*")
# red for numpy.log()
plt.plot(out_array, in_array,
color = 'red', marker = "o")
plt.title("numpy.log()")
plt.xlabel("out_array")
plt.ylabel("in_array")
plt.show()
输出:
out_array : [ 0. 0.18232156 0.33647224 0.47000363 0.58778666 0.69314718]
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。