1

I have numpy array like below I want to count total times columnsa>1 and columnsb<1

array

   [[1.2, 0.693],
   [1.2, 0.724],
   [0.976, 0.039],
   [0.987, 0.725],
   [0.979, 0.528],
   [0.978, 0.600],
   [0.983, 0.654],
   [0.986, 0.059],
   [0.979, 0.644],
   [0.982, 0.468]])]

Answer should yield 2

1 Answer 1

4

We can obtain the first column with arr[:,0] and the second with arr[:,1]. We can then make checks with arr[:,0] > 1 and arr[:,1] < 1. By using an AND operator (&), we obtain an array where an element is True if and only if the two corresponding elements are True. Finally we can sum up the booleans to obtain the number of times this is True:

>>> ((arr[:,0] > 1) & (arr[:,1] < 1)).sum()
2
Sign up to request clarification or add additional context in comments.

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.