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 to get an element of a NumPy list without bracket and ''

I have a NumPy list (Distances). When I print it, the result is:

array([[  1.        ],
       [600.        ],
       [456.03971033],
       [294.94188261],
       [286.47232436],
       [ 92.08606785]])

However, I want to get any specific element of this list as a float number without any brackets, array, and ” sign. Note that I don’t want to print it, I need to have the number in another variable like this:

element1 = Distance[0]

Result is: array([1.])

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

But I want it to be just: 1.

>Solution :

You can first flatten the array to make it one dimensional:

flatdistance = Distance.flatten()
element1 = flatdistance[0]
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