ในการคำนวณไฮเปอร์โบลิกแทนเจนต์ขององค์ประกอบอาร์เรย์ ให้ใช้เมธอด numpy.tanh() ใน PythonNumpy วิธีการนี้เทียบเท่ากับ np.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
รับแทนเจนต์ตรีโกณมิติไฮเปอร์โบลิกขององค์ประกอบอาร์เรย์ สร้างอาร์เรย์โดยใช้เมธอด array() ใน Numpy −
arr = np.array((0., 30., 45., 60., 90., 180., np.pi*1j/2, np.pi*1j))
กำลังแสดงอาร์เรย์ของเรา -
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) ในการหาไฮเปอร์โบลิกแทนเจนต์ขององค์ประกอบอาร์เรย์ ให้ใช้วิธี numpy.tanh() ใน PythonNumpy -
print("\nResult...\n",np.tanh(arr)) ตัวอย่าง
import numpy as np
# To compute the Hyperbolic tangent of the array elements, use the numpy.tanh() method in Python Numpy
# The method is equivalent to np.sinh(x)/np.cosh(x) or -1j * np.tan(1j*x).
print("Get the Trigonometric Hyperbolic tangent of the array elements...\n")
# Create an array using the array() method in Numpy
arr = np.array((0., 30., 45., 60., 90., 180., np.pi*1j/2, np.pi*1j))
# 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 the hyperbolic tangent of the array elements, use the numpy.tanh() method in Python Numpy
print("\nResult...\n",np.tanh(arr)) ผลลัพธ์
Get the Trigonometric Hyperbolic tangent of the array elements... Array... [ 0.+0.j 30.+0.j 45.+0.j 60.+0.j 90.+0.j 180.+0.j 0.+1.57079633j 0.+3.14159265j] Our Array type... complex128 Our Array Dimensions... 1 Number of elements... 8 Result... [0.+0.00000000e+00j 1.+0.00000000e+00j 1.+0.00000000e+00j 1.+0.00000000e+00j 1.+0.00000000e+00j 1.+0.00000000e+00j 0.+1.63312394e+16j 0.-1.22464680e-16j]