stackoverflow,
I have a matrix containing complex numbers (ex. -2.2982235934153075E-11+2.1179547211742553E-9i) that I need to import to a numpy array. I\'ve been us
The following might be an option to obtain a NumPy array from multi-column complex-numbered .csv file:
Say we have a file.csv
containing two rows and three columns of complex numbers:
-0.00034467+0.j, 0.00493246+0.j, 0.00365753-0.00361799j
-0.00782533-0.00081274j,-0.00402968+0.01065282j,-0.01345174+0.00464461j
The following will yield a NumPy array:
filename = 'file.csv'
data = pd.read_csv(filename, sep=",", header=None)
data = data.applymap(lambda s: np.complex(s.replace('i', 'j'))).values
Checking if data
is a NumPy array:
>> type(data)
numpy.ndarray
PS: The answer is based on this answer.