1

I want to calculate the minimum and maximum values of array A but I want to exclude all values less than 1e-12. I present the current and expected outputs.

import numpy as np
A=np.array([[9.49108487e-05],
       [1.05634586e-19],
       [5.68676707e-17],
       [1.02453254e-06],
       [2.48792902e-16],
       [1.02453254e-06]])

Min=np.min(A)
Max=np.max(A)
print(Min,Max)

The current output is

1.05634586e-19 9.49108487e-05

The expected output is

1.02453254e-06 9.49108487e-05

3 Answers 3

3

Slice with boolean indexing before getting the min/max:

B = A[A>1e-12]
Min = np.min(B)
Max = np.max(B)
print(Min, Max)

Output: 1.02453254e-06 9.49108487e-05

B: array([9.49108487e-05, 1.02453254e-06, 1.02453254e-06])

Sign up to request clarification or add additional context in comments.

Comments

2

You can just select the values of the array greater than 1e-12 first and obtain the min and max of that:

>>> A[A > 1e-12].min()
1.02453254e-06
>>> A[A > 1e-12].max()
9.49108487e-05

Comments

1
arr = np.array([9.49108487e-05,1.05634586e-19,5.68676707e-17,1.02453254e-06,2.48792902e-16,1.02453254e-06]) 
mask = arr > 1e-12 
Min = np.min(arr[mask]) 
Max = np.max(arr[mask])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.