2016-02-05 47 views
0

我已經寫在python以下代碼:不真值加上不受支持的操作數類型的錯誤

def FindDeviation(block, v, win): 
    h, w = block.shape 
    dist = 0 
    Dist = 0 
    for i in range(0,h-1): 
     for j in range(0,w-1): 
      print v 
      print block[i,j] 
      dist = (v-block[i,j]) 
      print dist 
      dist2 = int(dist)^2 
      print dist2 
      Dist = Dist + dist2 
      print Dist 
    DeviationOfBlock = math.sqrt((1/win^2)*Dist) 
    return DeviationOfBlock 

,其結果是,例如用於一個塊:

v = 82.0 
block[i,j] = 1 
dist = 81.0 
dist2 = 83 
Dist = 83 

然而,考慮V,塊[i,j] dist具有真實值,dist2不支持2 !!!!!爲什麼?是什麼原因? 最後一些步驟後,我有一個錯誤:

"TypeError: unsupported operand type(s) for ^: 'numpy.float64' and 'int'"

你能幫幫我嗎?

感謝和問候。

+0

如果你想迭代整個塊使用範圍(h)和範圍(w)'。如果您不明白原因,請測試這些表達式。 – hpaulj

回答

3

在python中,電源運營商是**,^意思是按位xor

In [12]: np.array([1,2,3])**2 
Out[12]: array([1, 4, 9]) 
相關問題