有一个功能:
def get_acc(real_dpt, real_avg, pre_dpt, pre_avg, axis):
delta_Rf = pre_dpt/pre_avg
delta_Rf_avg = pre_avg
delta_Ro = real_dpt / real_avg
delta_Ro_avg = real_avg
pre = delta_Rf - delta_Rf_avg
obs = delta_Ro - delta_Ro_avg
d1 = np.sum(pre*obs, axis=axis)
d2 = (np.sum(pre**2, axis=axis)*np.sum(obs**2, axis=axis))**0.5
return d1/d2
前:
obs_DPT, obs_AVG, cwrf_DPT, cwrf_AVG ,The same ndarray shape is passed in,
Shape = (29, 1452, 5), dtype = np.float32
我有
result1 = get_acc(obs_DPT, obs_AVG, cwrf_DPT, cwrf_AVG, axis=1)
# result1.shape = (29, 5) array
没有问题
然后,我得到了
result2 = get_acc(obs_DPT[i, :, 2:3], obs_AVG[i, :, 2:3], cwrf_DPT[i, :, 2:3], cwrf_AVG[i, :, 2:3], axis=0)
# i is 0, 1, 2, 3,...,28
# result2.shape=(1,)
现在,我使 result3 = result1[i, 2:3]
result3 = result1[i, 2:3]
# result3.shape=(1,)
然后我做出判断
if result2[0] == result3[0] :
print("i={}, resul2={}, resul3={}".format(i, resul2[0], resu3[0]))
对于 28 i,只有以下是相等的
i=4, resul2=0.9601920247077942, resul3=0.9601920247077942
i=21, resul2=0.966850221157074, resul3=0.966850221157074
i=27, resul2=0.9409129023551941, resul3=0.9409129023551941
其他人不平等
i=0, resul2=0.9641021490097046, resul3=0.9641022682189941
i=1, resul2=0.937653124332428, resul3=0.9376530647277832
i=2, resul2=0.9460444450378418, resul3=0.9460448026657104
i=3, resul2=0.9394290447235107, resul3=0.9394280314445496
i=5, resul2=0.9721810221672058, resul3=0.9721801280975342
i=6, resul2=0.9628128409385681, resul3=0.9628139734268188
i=7, resul2=0.9723774790763855, resul3=0.9723766446113586
i=8, resul2=0.9653074741363525, resul3=0.9653091430664062
i=9, resul2=0.9601299166679382, resul3=0.9601304531097412
i=10, resul2=0.9747092127799988, resul3=0.9747100472450256
i=11, resul2=0.9554705023765564, resul3=0.9554708003997803
i=12, resul2=0.9655697345733643, resul3=0.9655706286430359
i=13, resul2=0.9721916317939758, resul3=0.9721908569335938
另外,我还有一个问题
数组dtype = np.float32
当我制作数组时dtype = np.float64
我没有得到平等result2的result3
不知道我说清楚了没有,如何解决这个问题
十分感谢
守候你守候我
相关分类