ในการส่งคืนผลลัพธ์ของกำลังซึ่งค่าอินพุตถูกยกขึ้นด้วย scimath ให้ใช้วิธี scimath.power() ใน Python ส่งกลับ x ยกกำลัง p นั่นคือผลลัพธ์ของ x**p ถ้า x และ p เป็นสเกลาร์ ค่านั้นจะออก มิฉะนั้น อาร์เรย์จะถูกส่งคืน ถ้า x มีค่าลบ ผลลัพธ์จะถูกแปลงเป็นโดเมนที่ซับซ้อน พารามิเตอร์ x คือค่าอินพุต
พารามิเตอร์ p คือกำลังที่ x ถูกยกขึ้น ถ้า x มีหลายค่า p ต้องเป็นสเกลาร์หรือมีค่าเท่ากับ x ในกรณีหลัง ผลลัพธ์คือ x[0]**p[0], x[1]**p[1], ....
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import numpy as np
การสร้างอาร์เรย์ numpy โดยใช้เมธอด array() -
arr = np.array([2, 4, 8, 16, 32])
แสดงอาร์เรย์ -
print("Our Array...\n",arr) ตรวจสอบขนาด -
print("\nDimensions of our Array...\n",arr.ndim)
รับประเภทข้อมูล -
print("\nDatatype of our Array object...\n",arr.dtype) รับรูปร่าง -
print("\nShape of our Array object...\n",arr.shape) หากต้องการส่งคืนผลลัพธ์ของกำลังซึ่งค่าอินพุตถูกยกขึ้นด้วย scimath ให้ใช้วิธี scimath.power() ใน Python -
print("\nResult...\n",np.emath.power(arr, 2)) ตัวอย่าง
import numpy as np
# Creating a numpy array using the array() method
arr = np.array([2, 4, 8, 16, 32])
# Display the array
print("Our Array...\n",arr)
# Check the Dimensions
print("\nDimensions of our Array...\n",arr.ndim)
# Get the Datatype
print("\nDatatype of our Array object...\n",arr.dtype)
# Get the Shape
print("\nShape of our Array object...\n",arr.shape)
# To return the result of the power to which the input value is raised with scimath, use the scimath.power() method in Python
print("\nResult...\n",np.emath.power(arr, 2)) ผลลัพธ์
Our Array... [ 2 4 8 16 32] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (5,) Result... [ 4 16 64 256 1024]