對(duì)4個(gè)subarray的檢測(cè)結(jié)果設(shè)置閾值,做判斷,保留其中至少2個(gè)subarray能夠檢測(cè)到的結(jié)果。思路是對(duì)于1來(lái)說(shuō),其余三個(gè)結(jié)果合并做差小于閾值,即滿足條件;然而還有2和3或者4,同時(shí)排出和1,這時(shí)候先做判斷,排除掉1和2已經(jīng)append的結(jié)果,然后做2和3、4;以此類推,3就只和4
def voting_scheme(arr1, arr2, arr3, arr4, thre=10):
valid_values = []
#-----------arr1 with arr2 or arr3 or arr4 ar all of them------------#
for i, num in enumerate(arr1):
other = np.hstack((arr2, arr3, arr4))
other = np.sort(other)
diff = abs(num - other)
# f_data = np.where(np.abs(f_data)<np.abs(thre_amp), f_data, thre_amp)
if np.any(diff <= thre):
valid_values.append(num)
#-----------arr2 with arr3 or arr4 or all of them------------#
arr2_ = arr2.copy()
J = []
for j, num in enumerate(arr2):
diff_arr1 = abs(num - arr1)
if np.any(diff_arr1 <=thre):
J.append(j)
arr2_ = np.delete(arr2_, J)
for j, num in enumerate(arr2_):
other = np.hstack((arr3, arr4))
other = np.sort(other)
diff = abs(num - other)
if np.any(diff <= thre):
valid_values.append(num)
#-----------arr3 with arr4------------#
arr3_ = arr3.copy()
K = []
for k, num in enumerate(arr3):
diff_arr12 = abs(num - np.hstack((arr1, arr2)))
if np.any(diff_arr12 <=thre):
K.append(k)
arr3_ = np.delete(arr3_, K)
for k, num in enumerate(arr3_):
other = arr4
diff = abs(num - other)
if np.any(diff <= thre):
valid_values.append(num)
return valid_values
def drop_elements(arr, threshold):
# Initialize a new empty list to store the indices of elements to keep
keep_indices = [0]
# Iterate through the array, starting from the second element
for i in range(1, len(arr)):
# If the difference between the current element and the last kept element is greater than the threshold,
# add the index of the current element to the list of indices to keep
if arr[i] - arr[keep_indices[-1]] > threshold:
keep_indices.append(i)
# Use the numpy indexing syntax to return the elements at the selected indices
return arr[keep_indices]