Я пытаюсь выполнить точечное произведение «пиксель изображения RGb» на «пиксель изображения в градациях серого» * 1001 *
И мне нужно назначить результат скалярного произведения на 2 оси (последняя ось) ori_img
создать изображение «пиксель за пикселем» из np_img_R и np_img_S
Код следующий:
# I have (826, 600, 3) 3D tensor, which will be used as final result RGB color image
ori_img=np.zeros((826, 600, 3))
# And I also have (826, 600, 3) 3D tensor np_img_R as RGB color image,
# and (826, 600) 2D matrix np_img_S as grayscale image
# I'd like to perform dot product of 2 axis of np_img_R (3 length list like [x x x])
# and one scalar value of np_img_S indexed by row and column indices
# And I'd like to assign result of dot product into 3 axis of ori_img like [92 22 12]
# So, I used double for loop
for i in range(0,825):
for j in range(0,599):
# np_img_R[i,j,:]: select all from last axis
# np_img_S[i,j]: index by row and column
# ori_img[i,j,:]: assign result of dot product into last axis
# to create new image
ori_img[i,j,:]=np.dot(np_img_R[i,j,:],np_img_S[i,j])
# And I checked whether "result of dot product" and "assigned value in ori_img 3D tensor" are same
print(np.dot(np_img_R[456,232,:],np_img_S[456,232]))
# [130 250 255]
print(ori_img.astype(int)[456,232,:])
# [130 250 255]
# Above results show same result
print(np.dot(np_img_R[825,599,:],np_img_S[825,599]))
[ 50 29 113]
print(ori_img.astype(int)[825,599,:])
[0 0 0]
# But above results show different result, actually ori_img is not assigned by result of dot product
print(np_img_R.shape)
# (826, 600, 3)
print(ori_img.shape)
# (826, 600, 3)
# Shape of both show same
Я бы хотел присвоить результат произведения точек на 3 оси ori_img
Как я могу это исправить?