14 lines
520 B
Python
14 lines
520 B
Python
|
import numpy as np
|
||
|
def Find_idx4Time(In_mat, t):
|
||
|
# In_mat: time array
|
||
|
# t = target time
|
||
|
In_mat = np.array(In_mat)
|
||
|
t = np.array(t)
|
||
|
if len(np.shape(t)) == 0:
|
||
|
return np.where(abs(In_mat - t) <= min(abs(In_mat - t)))[0][0]
|
||
|
else:
|
||
|
In_mat = In_mat.reshape((len(In_mat), 1))
|
||
|
t = t.reshape((1,len(t)))
|
||
|
target_time = np.matmul(np.ones((len(In_mat),1)), t)
|
||
|
diff_mat = target_time - In_mat
|
||
|
return np.where(abs(diff_mat) <= np.min(abs(diff_mat), axis = 0))
|