mask1 and mask2 are both boolean tensors filled with some amount of True and False along their 1 dimension.
In response to the second part of your question, in the end, I want A to actually be a mask for another tensor. Specifically, in my problem I have a loss function that outputs a (L,n,L,a) tensor of floats, but many of those values in the tensor I don’t need contributing to the final loss. In order to only have only specific entries contribute to the loss, I’m trying to create a mask tensor (A) that is also 4D, which only has True in the particular positions that I want contributing to the loss. I will then multiply the 4D loss tensor and the 4D mask together to zero out the unneeded contributions. Hopefully this clarifies a bit of context.
Here’s also a more concrete example:
import torch
L = 100
n = 5
a = 13
A = torch.zeros((L,n,L,a)).bool()
mask1 = torch.randint(0,2,(L,)).bool()
mask2 = torch.randint(0,2,(L,)).bool()
print(A[mask1,0].shape) # works fine
print(A[mask1,0,mask2,:3]) # error
It’s still not clear precisely what you want to do.
Speaking in terms of the simplified two-dimensional example, it looks like
you want to use mask1 to mask the rows of A and use mask2 to mask the
columns.
But how should this work?
Do you want to keep all rows where mask1 is True and all columns where mask2 is True?
Do you only want to keep elements for which both mask1 and mask2 are True?