Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I get rid of unnecessary dot symbol for float ending with 0

For example I have an array in Python that looks like this

x = np.array([0, 1, 1.5, 2])

But when I do a print(x), it shows this instead

x = [0.  1.  1.5 2. ]

How do I make it so that it prints x = [0 1 1.5 2] without the "." symbol for numbers that don’t have any other decimals?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Since you have a NumPy array of floats you get the dots when you print. To just print them without dots you have to convert the numbers in your list to integers if they can be represented as an integer.

print([int(y) if y.is_integer() else y for y in x])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading