0

I have a set of data I want to process from a text file where each line is to be a numpy array. Some are easy to convert to arrays using the fromstring method, but other have scientific notation entries within them. How would I go about converting those into a np array?

My data looks like (this would have to be one array):

0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
  0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
  0.00000000e+00 8.02796109e-07 0.00000000e+00 0.00000000e+00
  0.00000000e+00 0.00000000e+00 9.99999197e-01        

2 Answers 2

1

I'd do

np.array(x.split(), dtype=np.float)

where x is your string

Sign up to request clarification or add additional context in comments.

Comments

1

Do you mean:

import numpy as np
nn = np.array(['0.00122300e+10', '43434'])
nn = nn.astype(float)
print (nn)
#array([12230000.,    43434.])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.