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

Printing values of a certain order in Python

I have an array A. I want to print number of values which are of the order: 1e2 and also the specific values. I present the current and expected outputs.

import numpy as np

A=np.array([ 4.22134987e+02,  4.22134987e+02,  4.22134987e+02,  4.22134987e+02,
        4.22134987e+02, -7.07598661e-11, -6.80734822e-11,  8.24084601e-11])

B=A[A==1e2]
print(B)

The current output is

[]

The expected output is

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

[5,4.22134987e+02]

>Solution :

1e2 is 100.00

import numpy as np

A=np.array([ 4.22134987e+02,  4.22134987e+02,  4.22134987e+02,  4.22134987e+02,
        4.22134987e+02, -7.07598661e-11, -6.80734822e-11,  8.24084601e-11])

B=A[A>=1e2]  #or B=A[A>=100]
[len(B),*set(B)]

#output
[5, 422.134987]
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