1

I have two arrays. Let's say they look like this:

    time1 = [ 1 2 3 ] and time2 = [ 2 4 6]
            [ 4 5 6 ]         
            [ 7 8 9 ]         

I would like to select only the rows from time1 for which the first column is within the range of time2. For example, from this data set, I would plot the [4 5 6] row, because 4 is in the range of 2 - 6. I am trying to select the rows from array time1 like this:

selectedtimes = time1(any(time1[:,0] < time2[-1]) and any(time1[:,0] > time2[0]))

I am currently receiving the object not callable error (shown below), and am quite stuck. Is there a better way to rewrite this line?

'numpy.ndarray' object is not callable

Help appreciated!

2 Answers 2

3

You can use numpy.logical_and here:

>>> np.logical_and(time1[:,0] > time2[0], time1[:,0] < time2[-1] )
array([False,  True, False], dtype=bool)
>>> time1[np.logical_and(time1[:,0] > time2[0], time1[:,0] < time2[-1] )]
array([[4, 5, 6]])
Sign up to request clarification or add additional context in comments.

Comments

0

Using for and if:

>>> time1 = ((1,2,3),(4,5,6),(7,8,9))
>>> time2 = (2,4,6)
>>> for x in time1:
...  if x[0] in time2:
...   print x
... 
(4, 5, 6)
>>> 

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.