[Numpy-discussion] manipulating lists
josef.pktd at gmail.com
josef.pktd at gmail.com
Tue Mar 24 10:27:18 EDT 2009
On Tue, Mar 24, 2009 at 10:14 AM, Nils Wagner
<nwagner at iam.uni-stuttgart.de> wrote:
> Hi all,
>
> How can I extract the numbers from the following list
>
> ['&', '-1.878722E-08,', '3.835992E-11',
> '1.192970E-03,-5.080192E-06']
>
> It is easy to extract
>
>>>> liste[1]
> '-1.878722E-08,'
>>>> liste[2]
> '3.835992E-11'
>
> but
>
>>>> liste[3]
> '1.192970E-03,-5.080192E-06'
>
> How can I accomplish that ?
>
in python I would do this:
>>> ss=['&', '-1.878722E-08,', '3.835992E-11','1.192970E-03,-5.080192E-06']
>>> li = []
>>> for j in ss:
for ii in j.split(','): # assumes "," is delimiter
try: li.append(float(ii));
except ValueError: pass
>>> li
[-1.8787219999999999e-008, 3.8359920000000003e-011, 0.00119297,
-5.0801919999999999e-006]
>>> np.array(li)
array([ -1.87872200e-08, 3.83599200e-11, 1.19297000e-03,
-5.08019200e-06])
Josef
More information about the NumPy-Discussion
mailing list