0

Below is a (1,3) array that represents the world coordinates of detected car's Centroid:

World_Point=[[3.27996023 0.29204794 1.        ]]

How can I turn the float numbers into the format shown below?

World_Point=[[3.27 0.29 1]]
jps
  • 20,041
  • 15
  • 75
  • 79
Khaled
  • 555
  • 1
  • 6
  • 26
  • Does this help? https://stackoverflow.com/questions/783897/truncating-floats-in-python – g_bor Oct 04 '20 at 12:48
  • 2
    Does this answer your question? [How to round a numpy array?](https://stackoverflow.com/questions/46994426/how-to-round-a-numpy-array) – JenilDave Oct 04 '20 at 13:05
  • @JenilDave. Thanks man. Apparently, my question is duplicated – Khaled Oct 04 '20 at 13:48

3 Answers3

2

What you need is the round(number, ndigits) function.

Nilesh PS
  • 356
  • 3
  • 8
2

do this for two decimal points :

result = (round(Wprld_Point, 2))

or as for list

for x in World_Point:



  (round(x, 2))
1
World_Point=[[3.27996023, 0.29204794, 1.0  ]]

def myround(numbers):
    return [round(x,2) for x in numbers]


World_Point = list(map(myround, World_Point))

print(World_Point)

Hocli
  • 146
  • 3