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

คำนวณอาร์คโคไซน์ด้วย scimath ใน Python

ฟังก์ชัน numpy.emath.arccos() คำนวณ arccos สำหรับค่าจริงที่ |x| <= 1 ได้ค่าจริงในช่วง [0, π] มิฉะนั้นได้ค่าเชิงซ้อน

ขั้นตอน

import numpy as np

arr = np.array([1, -1, 2, 0])
print("Array...\n", arr)
print("\nOur Array type...\n", arr.dtype)
print("\nOur Array Dimensions...\n", arr.ndim)
print("\nNumber of elements...\n", arr.size)
print("\nResult...\n", np.emath.arccos(arr))

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

import numpy as np

arr = np.array([1, -1, 2, 0])
print("Array...\n", arr)
print("\nOur Array type...\n", arr.dtype)
print("\nOur Array Dimensions...\n", arr.ndim)
print("\nNumber of elements...\n", arr.size)
print("\nResult...\n", np.emath.arccos(arr))

ผลลัพธ์

Array... [ 1 -1 2 0]
Our Array type... int64
Our Array Dimensions... 1
Number of elements... 4
Result... [0. -0.j 3.14159265-0.j 0. -1.3169579j 1.57079633-0.j ]