热线电话:13121318867

登录
2019-01-10 阅读量: 675
numpy通用类型操作

通用函数(ufunc):NumPy提供熟悉的数学函数,如sin,cos,exp等。这些函数也在元素上以元素方式运行,产生一个数组作为输出。

注意:我们上面使用重载运算符执行的所有操作都可以使用ufuncs来完成,如np.add,np.subtract,np.multiply,np.divide,np.sum等。

# Python program to demonstrate
# universal functions in numpy
import numpy as np

# create an array of sine values
a = np.array([0, np.pi/2, np.pi])
print ("Sine values of array elements:", np.sin(a))

# exponential values
a = np.array([0, 1, 2, 3])
print ("Exponent of array elements:", np.exp(a))

# square root of array values
print ("Square root of array elements:", np.sqrt(a))在IDE上运行

输出:

数组元素的正弦值:[0.00000000e + 00 1.00000000e + 00 1.22464680e-16]
数组元素的指数:[1. 2.71828183 7.3890561 20.08553692]
数组元素的平方根:[0。1. 1.41421356 1.73205081]
0.0000
3
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子