0

So I have following code snippet:

with open('dataset/train/problem.csv', 'r') as p:
raw_x = csv.reader(p)
data_x = []
for ix in raw_x:
    data_x.append([float(i) for i in ix])
print(data_x)

This prints the following output:

[[217.0, 118.0, 0.63, 755.0, 1071.0], [217.0, 118.0, 0.63, 755.0, 1071.0],...]

Now I am trying to convert this structure into a numpy array of floats so that I can use it with scikit-learn as an observation input. But when I try doing following

X = np.array(data_x)
print(X)

It gives the following result:

[  2.17000000e+02   1.18000000e+02   6.30000000e-01   7.55000000e+02
1.07100000e+03]
...
[  2.17000000e+02   1.18000000e+02   6.30000000e-01   7.55000000e+02
1.07100000e+03]

It's still float but the decimal values are not correct.

Been trying to figure out why this is happening as the source array is also in floats. I have tried providing type=float and astype as well but nothing seems to work.

Thanks!

2 Answers 2

1

The values in the array are the same. For example, 2.1700000000e+2 is 2.17 x 10^2, or 217, which is the same as in your original array.

The numpy array uses scientific notation instead of standard decimal form.

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

1 Comment

I am not very experienced with it, but I believe so.
0

The values are the same in the list and the array. It is just a different representation.

You can format a Python float in scientific notation:

>>> '{:e}'.format(11.7)
'1.170000e+01'

NumPy uses this kind of representation. That's all.

1 Comment

Yes. NumPy arrays can be used with most (all?) Python packages that work with array data types.

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.