0

The code down below finds the index of newdates within Setups with the init_location function. Then I increment the index by one to get the next date. But I cannot add to the init_location function. How would I be able to do that and get the expected value?

import numpy as np 

Setups = np.array(['2017-09-15T07:11:00.000000000', '2017-09-15T11:25:00.000000000',
                   '2017-09-15T12:11:00.000000000', '2017-12-22T03:14:00.000000000',
                   '2017-12-22T03:26:00.000000000', '2017-12-22T03:31:00.000000000',
                   '2017-12-22T03:56:00.000000000'],dtype="datetime64[ns]")
    

newdates = np.array(['2017-09-15T07:11:00.000000000','2017-12-22T03:26:00.000000000'],dtype="datetime64[ns]")
init_location= np.where(np.in1d(Setups,newdates[1]))
print("init location: ", Setups[init_location],"Address right after: ",Setups[init_location+1])

Output Error

TypeError: can only concatenate tuple (not "int") to tuple

Expected Output

init location: 2017-12-22T03:26:00. Address right after: 2017-12-22T03:31:00.00
1
  • you'll want np.nonzero; something like init_location = np.nonzero(np.in1d(Setups, newdates[1]))[0][0] Commented Jul 28, 2021 at 6:35

1 Answer 1

0

becuase init_location is a tuple, you cannot add "1" directly . Instead use the following format.

print("init location: ", Setups[init_location],"Address right after: ",Setups[init_location[0]+1])
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you it works but it prints like this ['2018-11-14T16:21:00.000000000'] - ['2018-12-09T08:43:00.000000000'] is there anychance I could make it print like '2018-11-14 16:21:00 - 2018-12-09 08:43:00
you can change the code to as follows init_location= np.where(np.in1d(Setups,newdates[1]))[0][0] print("init location: ", Setups[init_location],"Address right after: ",Setups[init_location+1])

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.