How to generate a tensor representing, for each pair of rows in a matrix, whether elements at the same position both = 1?
I'm trying to compare every row in a matrix to every other row in the same matrix, yielding, for each pair, a row showing whether each element of those two rows both equal 1.
Example: if I have this matrix as input:
[[1,0,1],
 [0,1,1],
 [0,0,0]]

I'd want to get this tensor:
[[[1,0,1],
  [0,0,1],
  [0,0,0]],
 [[0,0,1],
  [0,1,1]
  [0,0,0]],
 [[0,0,0],
  [0,0,0],
  [0,0,0]]]

Alternatively, if it's easier, my eventual goal is to reduce this tensor down to a matrix where each row represents whether ANY elements in a pair of rows from the original matrix both =1. So, the tensor above would get reduced to:
[[1,1,0],
 [1,1,0],
 [0,0,0]]

If it's easier to go straight to that without going through the intermediate tensor, let me know.

This is somewhat a partial answer, but it solves the first step which seems to be the question at hand:
import numpy as np

x = np.array([[1,0,1],
              [0,1,1],
              [0,0,0]])

output = x * np.repeat(x[:, np.newaxis, :], 3, axis=1)

output
# array([[[1, 0, 1],
#         [0, 0, 1],
#         [0, 0, 0]],

#        [[0, 0, 1],
#         [0, 1, 1],
#         [0, 0, 0]],

#        [[0, 0, 0],
#         [0, 0, 0],
#         [0, 0, 0]]])

In PyTorch, it would be:
import torch

x = torch.tensor([[1,0,1],
                  [0,1,1],
                  [0,0,0]])

output = x * x.unsqueeze(1).repeat_interleave(3, dim=1)

