如何找到我在 Python 中拥有的每个其他元素 2 数组的平均值?

问题描述 投票:0回答:0

在这些数组中: 上限:[4135 4148 4161 4174] 较低范围:[4121 4108 4095 4082]

我试图找到所有其他元素的平均值。所以从 4135 和 4121 开始,找到它旁边的值的平均值。所以 4135-4148 和 4161-4174 与较低范围的数组相同。

代码如下:

def fifty_calc(start1, stop1, step1, start2, stop2, step2):
    original_range = np.arange(start1, stop1, step1)
    lower_range = np.arange(start2, stop2, step2)
    mean_of_first_values = np.mean(original_range[:2])
    mean_of_second_values = np.mean(original_range[-2:])
    lower_mean_value_1 = np.mean(lower_range[:2])
    lower_mean_value_2 = np.mean(lower_range[-2:])
    mid_m = np.mean(original_range[1:3])
    low_m = np.mean(lower_range[1:3])
    m_of_first_vals = (original_range[0] + lower_range[0]) / 2
    upper_mean_array = np.array([mean_of_first_values, mid_m, mean_of_second_values])
    lower_mean_array = np.array([lower_mean_value_1, low_m, lower_mean_value_2])


    return (original_range, mean_of_first_values, mean_of_second_values,
            upper_mean_array, lower_range, lower_mean_value_1,
            lower_mean_value_2, mid_m, low_m, m_of_first_vals, lower_mean_array)

o_rng, m_fst, m_snd, u_mean_arr, l_rng, l_mn_fst, l_mn_snd, m_mid, m_low, first_val_m, 
l_mean_arr = fifty_calc(4135, 4175, 13, 4121, 4081, -13)



zeros = np.zeros((1, 3))
zeros[0, 0] = first_val_m
zeros_flat = zeros.flatten()
mean_for_all_ranges = np.concatenate((u_mean_arr, zeros_flat, l_mean_arr))
python arrays numpy statistics mean
© www.soinside.com 2019 - 2024. All rights reserved.