Rename directory applicationCode -> src
This commit is contained in:
14
src/util/Find_idx4Time.py
Normal file
14
src/util/Find_idx4Time.py
Normal file
@@ -0,0 +1,14 @@
|
||||
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))
|
||||
Reference in New Issue
Block a user