forループからベクトル化numpy操作への非常に簡単な移行では、バグを把握することはできません。それは2D行列間の単純な加算であるので、コードは以下のpython forループと3次元numpy行列の加算との等価性
for null_pos in null_positions:
np.add(singletree[null_pos, parent.x, :, :],
posteriors[parent.u, null_pos, :, :],
out=singletree[null_pos, parent.x, :, :])
で、私は3Dに加え
np.add(singletree[null_positions, parent.x, :, :],
posteriors[parent.u, null_positions, :, :],
out=singletree[null_positions, parent.x, :, :])
に一般化することは、結果が異なって表示されます、です!なぜ見えますか?
ありがとうございます!
更新:
singletree[null_positions, parent.x, :, :] = \
posteriors[parent.u, null_positions, :, :] +
singletree[null_positions, parent.x, :, :]
が問題を解決しているようです。これは、追加操作に関して何が違うのですか?
入力配列の形状は何ですか? –
singletreeはL x M x C x(C + 1)の行列で、posteriorsはN x L x C x(C + 1)です。それは次元に依存しないので私の更新を見てください(私は1分で投稿します)、私は信じています – diningphil