np.sin()是一个numpy 库函数,用于生成函数内传递的角度的正弦值。
语法
numpy.sin(x, /,out=None,*,where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'sin'>
参数
np.sin() 函数需要一个必要的参数作为参数。
- x:这是要传递给函数的角度。这个角度的单位是弧度。这是计算正弦值的必要参数。
- out:我们可以指定我们要存储输出值的位置。默认情况下,这个参数的值保持为None。
- where:如果这个条件是True,那么ufunc的结果将被存储;如果这个条件是False,那么原始值将被保留。
返回值
它返回一个单一的值。它返回函数内部传递的角度的正弦值。
使用 np.sin() 查找 pi / 4 的值的 Python 程序
# importing numpy as np
import numpy as np
# creating an numpy element
ele = np.pi / 4
# storing the sine value to the variable.
sine = np.sin(ele)
print(sine)
输出
0.7071067811865475
在这个程序中,我们导入了numpy库并创建了一个元素来存储π的值**,并使用名为np.pi的numpy函数来使用 π 。因此,π/2 被存储在名为ele的变量中。这个角度被传递到名为 sin() 的函数里面。这个sin函数从这个角度找到合适的正弦值。最后,我们打印出正弦值。
使用np.sin()查找pi/3值的Python程序
# Importing numpy as np
import numpy as np
# Storing the sine value to the variable.
sine = np.sin(np.pi / 3)
print(sine)
输出
0.8660254037844386
在这个程序中,我们找到了π/3的正弦值。然后,我们把这个角度传给sin函数,得到正弦值。
使用np.sin()查找0到pi/2的值的Python程序
# Importing numpy as np
import numpy as np
# Creating an array for storing angles
arr = np.array((0, 30, 45, 60, 90))
np.pi/180
# Finding the sine values for the angles
sine = np.sin(arr)
print(sine)
输出
[ 0. -0.98803162 0.85090352 -0.30481062 0.89399666]
在这个程序中,我们导入了numpy并创建了一个numpy数组来存储角度。numpy数组包括0、30、45、60和90的角度。我们使用sin函数找到这些角度的正弦值。在这个程序中,我们在sin()函数里面传递了一个数组。
Python中的np.sin() 函数就到此为止。