Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

คำนวณ inverse hyperbolic cosine (arccosh) ใน Python ด้วย numpy.arccosh()

ฟังก์ชัน arccosh() เป็น multivalued function สำหรับ x แต่ละค่า มี z หลายค่าที่ cosh(z)=x มาตรฐานคือคืน z ที่ imaginary part อยู่ใน [-π, π] และ real part ใน [0, inf] สำหรับอินพุทจริง จะคืนค่าจริงเสมอ ค่าที่ไม่สามารถแสดงเป็นจริงได้จะคืน nan

พารามิเตอร์สำคัญ

  • x: อาร์เรย์อินพุต
  • out, where (ไม่บังคับ): คล้าย ufunc อื่นๆ

ขั้นตอนการใช้งาน

import numpy as np

คำนวณ arccosh ค่าต่างๆ

print("Get the Trigonometric inverse Hyperbolic cosine...")
print("\nResult...", np.arccosh(np.pi*1j))
print("\nResult...", np.arccosh(np.pi/2.))
print("\nResult...", np.arccosh(np.pi/3.))
print("\nResult...", np.arccosh(np.e))

โค้ดตัวอย่างสมบูรณ์

import numpy as np

print("Get the Trigonometric inverse Hyperbolic cosine...")
print("\nResult...", np.arccosh(np.pi*1j))
print("\nResult...", np.arccosh(np.pi/2.))
print("\nResult...", np.arccosh(np.pi/3.))
print("\nResult...", np.arccosh(np.e))

ผลลัพธ์ที่คาดหวัง

Get the Trigonometric inverse Hyperbolic cosine...
Result... (1.8622957433108482+1.5707963267948966j)
Result... 1.0232274785475506
Result... 0.30604210861326536
Result... 1.6574544541530771