I am working with 4-dimensional tensors, and I am using for loop to check the conditional flow, I wanted to know how can I implement the below code efficiently
## object_temp Shape -> (24, 7, 7, 30)
## Object Shape -> (24, 7, 7)
## target Shape -> ( 24, 7, 7, 30)
for i in range(object.shape[0]):
for j in range(object.shape[1]):
for k in range(object.shape[2]):
if ((target[i,j,k,4] >0) | (target[i,j,k,9] >0)):
object[i,j,k] = 1
object_temp[i,j,k,:] = 1
I am creating a mask only. I am new to PyTorch so my knowledge is limited, can you point to the functions which I shall use.
I am creating a mask for conditions:
Is there something I do not understand about your question? The following code does not throw an error and gives the same result as your code using loops: