在 Python 中獲取以度數表示的角度陣列的三角正弦值


要獲取以度數表示的角度陣列的三角正弦值,請在 Python Numpy 中使用 numpy.sin() 方法。該方法返回第一個引數 x 的每個元素的正弦值。如果 x 是標量,則返回標量。第一個引數 x 是以弧度表示的角度(2pi 表示 360 度)。這裡,它是一個角度陣列。第二個和第三個引數是可選的。

第二個引數是 ndarray,結果儲存到的位置。如果提供,則其形狀必須與輸入廣播到的形狀相同。如果未提供或為 None,則返回一個新分配的陣列。元組(僅可能作為關鍵字引數)的長度必須等於輸出的數量。

第三個引數是條件,在輸入上進行廣播。在條件為 True 的位置,out 陣列將設定為 ufunc 結果。在其他位置,out 陣列將保留其原始值。請注意,如果透過預設的 out=None 建立了一個未初始化的 out 陣列,則其中條件為 False 的位置將保持未初始化狀態。

步驟

首先,匯入所需的庫 -

import numpy as np

角度陣列的三角正弦。求 tan 0、tan 30、tan 45、tan 60、tan 90、tan 180 -

arr = np.array((0., 30., 45., 60., 90., 180.))

顯示我們的陣列 -

print("Array...\n",arr)

獲取資料型別 -

print("\nArray datatype...\n",arr.dtype)

獲取陣列的維度 -

print("\nArray Dimensions...\n",arr.ndim)

獲取陣列的元素個數 -

print("\nNumber of elements in the Array...\n",arr.size)

要查詢以度數表示的角度陣列的正弦值,請在 Python Numpy 中使用 numpy.sin() 方法 -

print("\nResult...",np.sin(arr * np.pi / 180. ))

示例

import numpy as np

# To get the Trigonometric sines of an array of angles given in degrees, use the numpy.sin() method in Python Numpy
# The method returns the sine of each element of the 1st parameter x. This is a scalar if is a scalar.

print("The Trigonometric sines of an array of angles...")

# Array of angles
# finding tan 0, tan 30, tan 45, tan 60, tan 90, tan 180
arr = np.array((0., 30., 45., 60., 90., 180.))

# Display the array
print("Array...\n", arr)

# Get the type of the array
print("\nOur Array type...\n", arr.dtype)

# Get the dimensions of the Array
print("\nOur Array Dimensions...\n",arr.ndim)

# Get the number of elements in the Array
print("\nNumber of elements...\n", arr.size)

# To find sines of an array of angles given in degrees, use the numpy.sin() method in Python Numpy
print("\nResult...",np.sin(arr * np.pi / 180. ))

輸出

The Trigonometric sines of an array of angles...
Array...
[ 0. 30. 45. 60. 90. 180.]

Our Array type...
float64

Our Array Dimensions...
1

Number of elements...
6

Result... [0.00000000e+00 5.00000000e-01 7.07106781e-01 8.66025404e-01
1.00000000e+00 1.22464680e-16]

更新於: 2022年2月25日

310 次檢視

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.