![](/img/trans.png)
[英]how do I parse certain data points from a .txt file through python 3.0
[英]How do I parse data points in numpy array python?
我有一個形狀為 (100,100) 的 numpy 陣列。 它的值如 -.320+0.323i。 如何將其分成兩個單獨的 numpy arrays,一個具有實際值,一個具有“i”值?
您可以像這樣使用內置 functions.real 和 .imag :
import numpy
a = numpy.array([1.+0.j, 1.+0.j, 1.+0.j])
realparts = a.real
imagparts = a.imag
假設您有一個名為 arr 的 numpy 數組。
import numpy as np
#Example numpy array with real and imaginary parts
arr = np.array([1, 2 + 3j, 3, 4 + 6j, 5 + 9j, 6])
print(arr.imag) #Prints imaginary parts of arr
print(arr.real) #Prints real parts of arr
這應該有效。
只需使用以下兩行:
# Assume A is the numpy.array
>>> A.real
>>> A.imag
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.