2

i am experiencing this behaviour:

import numpy
myArray = numpy.array([-31.279400000000003,-38.88999999999999,1.3008999999999986])

print(myArray)

Output:

array([-31.2794 -38.89     1.3009])

I don't understand the whitespaces before and after each items of array.

Should i report numpy bug?

Using Python 3.7, numpy 1.19.0, Ubuntu 19.10

EDIT: I accepted @paime answer, for printing tables it makes sense. But seems to me senseless for printing one row

1 Answers1

0

It is normal behavior.

Each number takes the same amount of space (padding included) so that everything is aligned.

See:

>>> print(np.array([[12.3, -12.345, 1.23456], [-12.345, 1.23456, 12.3]]))
[[ 12.3     -12.345     1.23456]
 [-12.345     1.23456  12.3    ]]
paime
  • 2,901
  • 1
  • 6
  • 17
  • Ah, right, when it is printed in table it makes sense. But "Each number takes the same amount of space" is not true, that was confusing me... the prior thing is that the dot is on same place to fit all numbers. But anyway for one row it is confusing – Zbyšek Zapadlík Jul 10 '20 at 11:01
  • Corrected to "Each number takes the same amount of space, **padding included**" – paime Jul 10 '20 at 11:09