1

I am trying find the entries in a two-dimensional array that are above a certain threshold. The thresholds for the individual columns is given by a one-dimensional array. To exemplify,

[[1, 2, 3],
 [4, 5, 6],
 [2, 0, 4]]

is the two-dimensional array and I want to see if where in the columns values are bigger than

[2, 1, 3]

so the output of running the operation should be

[[False, True, False]
 [True, True, True],
 [False, False, True]]

Thanks!

3
  • 2
    Something is wrong in your example. For example, why a True value corresponds to 0? 0 is clearly smaller than all your thresholds. Commented Jul 29, 2014 at 0:12
  • Changed clearly need a break Commented Jul 29, 2014 at 0:25
  • 1
    Still does not compute :) 6 is greater than any element, but has a False value. Commented Jul 29, 2014 at 0:28

2 Answers 2

3

Well, assuming there's an error in the example, I would simply do:

import numpy as np

A = np.array([[1, 2, 3],[4, 5, 6],[2, 0, 4]])
T = np.array([2, 1, 3])

X = A > T

Which gives

array([[False,  True, False],
   [ True,  True,  True],
   [False, False,  True]], dtype=bool)
Sign up to request clarification or add additional context in comments.

1 Comment

0

I think there may be inconsistencies in your example (e.g. 2 > 1 is True, yet 2 > 4 is True) - can you clarify this?

Assuming you you want to know, for each row, which columns of the values in the first list are greater than the [2,1,3] list you gave, I suggest the following:

import numpy as np

tmp = [[1, 2, 3],
      [4, 5, 6],
      [2, 0, 4]]

output = [ np.less([2, 1, 3], tmp[i]) for i in range(len(tmp))]

Similarly, try greater or greater_equal or less_equal for the result you're after: http://docs.scipy.org/doc/numpy/reference/routines.logic.html

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.