ในการคำนวณไฮเปอร์โบลิกแทนเจนต์ ให้ใช้เมธอด numpy.tanh() ใน Python Numpy เทียบเท่าtonp.sinh(x)/np.cosh(x) หรือ -1j * np.tan(1j*x) ส่งกลับค่าไฮเพอร์โบลิกแทนเจนต์ที่สอดคล้องกัน นี่คือสเกลาร์ถ้า x เป็นสเกลาร์ พารามิเตอร์ที่ 1 x คืออาร์เรย์อินพุต พารามิเตอร์ที่ 2 และ 3 เป็นทางเลือก
พารามิเตอร์ตัวที่ 2 คือ ndarray ซึ่งเป็นตำแหน่งที่เก็บผลลัพธ์ หากมีให้ต้องมีรูปร่างที่อินพุตออกอากาศไป หากไม่ระบุหรือไม่มี ระบบจะส่งคืนอาร์เรย์ที่จัดสรรใหม่
พารามิเตอร์ที่ 3 คือเงื่อนไขที่ออกอากาศผ่านอินพุต ที่ตำแหน่งที่เงื่อนไขเป็น True อาร์เรย์ out จะถูกตั้งค่าเป็นผลลัพธ์ ufunc ที่อื่น Out Array จะคงค่าเดิมไว้
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import numpy as np
รับแทนเจนต์ตรีโกณมิติไฮเปอร์โบลิก ค้นหา tanh −
print("\nResult...",np.tanh(np.pi*1j)) การหา tanh 90 องศา −
print("\nResult...",np.tanh(np.pi/2.)) การหา tanh 60 องศา −
print("\nResult...",np.tanh(np.pi/3.))
การหา tanh 45 องศา −
print("\nResult...",np.tanh(np.pi/4.)) การหา tanh 30 องศา −
print("\nResult...",np.tanh(np.pi/6.)) การหา tanh 0 องศา −
print("\nResult...",np.tanh(0)) ตัวอย่าง
import numpy as np
# To compute the Hyperbolic tangent, use the numpy.tanh() method in Python Numpy
# Equivalent to np.sinh(x)/np.cosh(x) or -1j * np.tan(1j*x).
# Returns the corresponding hyperbolic tangent values. This is a scalar if x is a scalar.
print("Get the Trigonometric Hyperbolic tangent...")
# find tanh
print("\nResult...",np.tanh(np.pi*1j))
# finding tanh 90 degrees
print("\nResult...",np.tanh(np.pi/2.))
# finding tanh 60 degrees
print("\nResult...",np.tanh(np.pi/3.))
# finding tanh 45 degrees
print("\nResult...",np.tanh(np.pi/4.))
# finding tanh 30 degrees
print("\nResult...",np.tanh(np.pi/6.))
# finding tanh 0 degrees
print("\nResult...",np.tanh(0)) ผลลัพธ์
Get the Trigonometric Hyperbolic tangent... Result... -1.2246467991473532e-16j Result... 0.9171523356672744 Result... 0.7807144353592677 Result... 0.6557942026326724 Result... 0.4804727781564516 Result... 0.0