当我使用数组时如何获得精确值?为什么结果是数组([0,0,0,0,0,0,0,0,0])而不是0.7?
overlap= np.array([0]*10)
tempi = np.zeros(10)
for i in range(10):
for j in range(10):
tempi[j] = 0.7;
overlap[i] = max(tempi)
print(max(tempi))
overlap
答案 0 :(得分:3)
overlap
(隐式)声明为整数数组。当您将浮点数分配给整数数组中的位置时,它们会被截断(隐式强制转换为整数)。
您要做的是宣布overlap
dtype
float
-
overlap = np.array([0] * 10, dtype=np.float)
或者,
overlap = np.array([0.] * 10)
再次运行,你会得到你期望的。