หากต้องการคืนค่าส่วนที่แท้จริงของอาร์กิวเมนต์ที่ซับซ้อน ให้ใช้เมธอด numpy.real() เมธอดส่งคืนองค์ประกอบจริงของอาร์กิวเมนต์ที่ซับซ้อน ถ้า val เป็นค่าจริง ชนิดของ val จะถูกใช้สำหรับเอาต์พุต หาก val มีองค์ประกอบที่ซับซ้อน ประเภทที่ส่งคืนจะเป็นแบบลอย พารามิเตอร์ที่ 1 val คืออาร์เรย์อินพุต นอกจากนี้เรายังจะเปลี่ยนส่วนที่แท้จริงของอาร์กิวเมนต์ที่ซับซ้อนโดยใช้ array.real
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น-
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.real() ใน Python เมธอดส่งคืนองค์ประกอบจริงของอาร์กิวเมนต์ที่ซับซ้อน ถ้า val เป็นค่าจริง ชนิดของ val จะถูกใช้สำหรับเอาต์พุต หาก val มีองค์ประกอบที่ซับซ้อน ประเภทที่ส่งคืนจะเป็นแบบลอย
พารามิเตอร์ที่ 1 val คืออาร์เรย์อินพุต -
print("\nReal part...\n",np.real(arr)) เปลี่ยนส่วนจริง -
arr.real = 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 real part of the complex argument, use the numpy.real() method in Python
print("\nReal part...\n",np.real(arr))
# Change the real part
arr.real = 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,) Real part... [36. 27. 68. 23.] Updated result... [5.+1.j 5.+2.j 5.+3.j 5.+2.j]