@abarnert's answer is fine, but don't forget that loadtxt has an argument, converters,
that provides a hook for customizing how a field is processed. Here are a couple
examples that show how it can be used to process this file.
In the first version, the default delimiter (whitespace) is retained,
so there are three columns.
usecols is used to ignore the middle column (the '+'). A converter is used to
convert the last column (column 2) to a floating point value. It uses a slice to discard
the last character, which is the 'i'. With these arguments, loadtxt returns an array
with shape (11, 2) of floating point values. By calling the view method with the
type np.complex128, the array is converted to an array of floating point values
with shape (11, 1). Finally, indexing with [:,0] gives the 1D array of complex values.
(A call to ravel, squeeze, or reshape could have been used instead.)
In [24]: loadtxt('file.txt', converters={2:lambda f: float(f[:-1])}, usecols=(0,2)).view(np.complex128)[:,0]
Out[24]:
array([ 25.000000+0.j , 8.438180-4.94194j , 4.468170-5.08305j ,
4.557640-3.02201j , 2.691380-5.43104j , -0.151334-4.83717j ,
1.983360-1.3339j , 3.590020-0.932973j, 1.427270-0.617317j,
1.020050-1.14214j , -0.155640+2.74564j ])
The next version treats the entire line as a single field. The following function
converts a string in the format used in the file to a complex number:
In [36]: def to_complex(field):
....: return complex(field.replace(' ', '').replace('+-', '-').replace('i', 'j'))
....:
E.g
In [39]: to_complex('8.43818 + -4.94194i')
Out[39]: (8.43818-4.94194j)
This call to loadtxt treats each line as a single field, and uses
the converter to convert each field to a complex number:
In [37]: loadtxt('file.txt', converters={0: to_complex}, dtype=np.complex128, delimiter=';')
Out[37]:
array([ 25.000000+0.j , 8.438180-4.94194j , 4.468170-5.08305j ,
4.557640-3.02201j , 2.691380-5.43104j , -0.151334-4.83717j ,
1.983360-1.3339j , 3.590020-0.932973j, 1.427270-0.617317j,
1.020050-1.14214j , -0.155640+2.74564j ])
(The delimiter is set to ';', but it could have been any character that
doesn't occur in the file.)