私はベクトル化に非常に苦労しています。数学についてまだそのように考えることができないようです。私は今これを持っています:
#!/usr/bin/env python
import numpy as np
import math
grid = np.zeros((2,2))
aList = np.arange(1,5).reshape(2,2)
i,j = np.indices((2,2))
iArray = (i - aList[:,0:1])
jArray = (j - aList[:,1:2])
print np.power(np.power(iArray, 2) + np.power(jArray, 2), .5)
私のプリントアウトは次のようになります。
[[ 2.23606798 1.41421356]
[ 4.47213595 3.60555128]]
私がやろうとしているのは、ピクセル値の 2D 配列グリッドを取得し、各ピクセルが重要なピクセルのリスト aList からどれだけ離れているかを言うことです。
# # @
# # #
* # *
たとえば、* (0,2) と (2,2) が重要なピクセルで、現在 @ (2,0) ピクセルにいる場合、@ ピクセルの値は次のようになります。
[(0-2)^2 + (2-0)^2]^.5 + [(2-2)^2 + (0-2)^2]^.5
すべてのグリッドはピクセル値を保持するため、距離を関連付けるために各ピクセル値のインデックスを取得する必要があります。ただし、私の Alist 配列は [x,y] 座標を保持しているため、簡単です。私は今、2 つの問題があると思います: 1. インデックスを正しく取得していません 2. aList の座標を適切にループしていません