# Row-wise or of shifted boolean 1-D tensors

I have a 1-D boolean tensor, let’s say, a = [True, False, False, False, True, False, True, False, False, False]. What I want to do is, for given N, I want to find bitwise_or of the tensors a, a[1:] + [False], a[2:] + [False, False], ..., a[N-1:] + [False, ..., False] (with abuse of notations). For example, when N=1, then the answer would be bitwise_or of two tensors
[True, False, False, False, True, False, True, False, False, False]
[False, False, False, True, False, True, False, False, False, False],
so is
[True, False, False, True, True, True, True, False, False, False].
I can do this with using a for loop over N, by

for i in range(1, N):
a = a | torch.cat(a[i:], torch.BoolTensor([False] * i))

but I wonder if there’s more efficient way to do this. Also, I want if there’s a way to do the same thing for numpy array.

hy @seewoo5, you can do something like this

b = torch.tensor((True,False))
c = torch.tensor((True,True))
j = torch.tensor(b.clone().detach() | c.clone().detach() )
print(j)
tensor([True, True])