-1

I have a script where I need to convert a list to a numpy array, but I'm having this weird problem and I don't know how to solve it.

>>> a = [6.27575197488659, 28.91240527183621, -0.005173032150138807]
>>> import numpy as np
>>> np.array(a)
array([ 6.27575197e+00,  2.89124053e+01, -5.17303215e-03])

The array should be the same as the list and you would safe my day by helping me.

Intonet
  • 3
  • 3

2 Answers2

2

It is the same! You can verify it simply by

list(np.array(a))

Only numpy represents the floats in the scientific (exp) format, that's all!

s0mbre
  • 361
  • 2
  • 14
-1

Update for 2023!!

Use

np.array(a,dtype='object')

Currently, it is showing VisibleDeprecationWarning, to avoid it, use dtype='object' while converting.

The question is duplicate of this question.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 24 '23 at 00:56
  • No, do not do this! You defeat the purpose of using numpy by setting `dtype=object`. – Pranav Hosangadi Feb 25 '23 at 07:21
  • Also if you think a question is a duplicate, flag/vote to close it as such once you've earned that [privilege](/help/privileges) – Pranav Hosangadi Feb 25 '23 at 07:22