numpy.exp()用法及代码示例
numpy.exp(array,out = None,where = True,cast =’same_kind’,order =’K’,dtype = None):
此数学函数可帮助用户计算输入数组中所有元素的指数。
参数:
array : [array_like] 我们需要测试的输入数组或对象的元素.
out : [ndarray, optional] 与输入数组具有相同维度的输出数组,放置在结果中.
** kwargs : 允许您将参数的关键字变量长度传递给函数。当我们要处理函数中的命名参数时使用它。
where : [array_like, optional] 真值表示计算该位置的通用函数(ufunc),假值表示将输出中的值单独保留.
返回:
具有输入数组所有元素的指数的数组。
代码1:工作
# Python program explaining
# exp() function
import numpy as np
in_array = [1, 3, 5]
print ("Input array : ", in_array)
out_array = np.exp(in_array)
print ("Output array : ", out_array)
输出:
Input array : [1, 3, 5] Output array : [ 2.71828183 20.08553692 148.4131591 ]
代码2:图形表示
# Python program showing
# Graphical representation of
# exp() 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.exp(in_array)
y = [1, 1.2, 1.4, 1.6, 1.8, 2]
plt.plot(in_array, y, color = 'blue', marker = "*")
# red for numpy.exp()
plt.plot(out_array, y, color = 'red', marker = "o")
plt.title("numpy.exp()")
plt.xlabel("X")
plt.ylabel("Y")
plt.show()
输出:
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。