It may be an easy problem but I could not find any practical solution. My code has following code segment involving 3 nested for loops. The target is to create a specialized intensity matrix for my algorithms for both prediction and ground_truth image matrix as follows:
for i in range (batch):
for j in range (img_width):
for k in range (img_height):
tensor=prediction[i][j][:]-prediction[i][k][:]
extracted_intensity_pred[i][j][k]=torch.norm(tensor, 2)
tensor=ground truth[i][j][:]-ground_truth[i][k][:]
extracted_intensity_ground_truth[i][j][k]=torch.norm(tensor, 2)
This nested for loop structure is slowing the execution intensively. Is there any broadcasting implementation(in numpy or pytorch tensor based) that may be used?