ในการส่งคืนส่วนจินตภาพของอาร์กิวเมนต์ที่ซับซ้อน ให้ใช้วิธี numpy.imag() ใน Python ชุดรูปแบบส่งคืนองค์ประกอบจินตภาพของอาร์กิวเมนต์ที่ซับซ้อน ถ้า val เป็นค่าจริง ชนิดของ val จะถูกใช้สำหรับเอาต์พุต หาก val มีองค์ประกอบที่ซับซ้อน ประเภทที่ส่งคืนจะเป็นแบบลอย พารามิเตอร์ที่ 1 val คืออาร์เรย์อินพุต นอกจากนี้เรายังจะอัปเดตส่วนจินตภาพของอาร์กิวเมนต์ที่ซับซ้อนโดยใช้ array.img
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import numpy as np
สร้างอาร์เรย์โดยใช้เมธอด array() -
arr = np.array([36.+1.j , 27.+2.j , 68.+3.j , 23.+2.j])
แสดงอาร์เรย์ -
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...\n",arr.shape)
ในการส่งคืนส่วนจินตภาพของอาร์กิวเมนต์ที่ซับซ้อน ให้ใช้วิธี numpy.imag() ใน Python ชุดรูปแบบส่งคืนองค์ประกอบจินตภาพของอาร์กิวเมนต์ที่ซับซ้อน ถ้า val เป็นค่าจริง ชนิดของ val จะถูกใช้สำหรับเอาต์พุต หาก val มีองค์ประกอบที่ซับซ้อน ประเภทที่ส่งคืนจะเป็นแบบลอย พารามิเตอร์ที่ 1 val คืออาร์เรย์อินพุต -
print("\nImaginary part...\n",np.imag(arr)) เปลี่ยนส่วนจินตภาพ -
arr.imag = 5
print("\nUpdated result...\n",arr) ตัวอย่าง
import numpy as np
# Create an array using the array() method
arr = np.array([36.+1.j , 27.+2.j , 68.+3.j , 23.+2.j])
# 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...\n",arr.shape)
# To return the imaginary part of the complex argument, use the numpy.imag() method in Python
print("\nImaginary part...\n",np.imag(arr))
# Change the imaginary part
arr.imag = 5
print("\nUpdated result...\n",arr) ผลลัพธ์
Our Array... [36.+1.j 27.+2.j 68.+3.j 23.+2.j] Dimensions of our Array... 1 Datatype of our Array object... complex128 Shape of our Array... (4,) Imaginary part... [1. 2. 3. 2.] Updated result... [36.+5.j 27.+5.j 68.+5.j 23.+5.j]