I would like to remove zero values from my tensors. My guess is to identify them using Nx.greater
and then Nx.take
the values I want to keep. I can’t quite get there and I may be totally off-base; thank you for the help.
Example Distance Matrix
pairwise distances: #Nx.Tensor<
f32[6][6]
[
[0.0, -0.56798702478, -1.72393488883, -1.87532353401, -2.15741109848, -5.3883495330],
[0.56798702478, 0.0, -1.15594792366, -1.30733656883, -1.58942413330, -4.8203625679],
[1.72393488883, 1.15594792366, 0.0, -0.151388645172, -0.433476209640, -3.6644146442],
[1.87532353401, 1.30733656883, 0.151388645172, 0.0, -0.28208756446, -3.5130259990],
[2.15741109848, 1.58942413330, 0.433476209640, 0.28208756446, 0.0, -3.230938434],
[5.3883495330, 4.8203625671, 3.6644146442, 3.5130259990, 3.230938434, 0.0]
]
nonzero = Nx.abs(distances) |> Nx.greater(0)
non-zero distances: #Nx.Tensor<
u8[6][6]
[
[0, 1, 1, 1, 1, 1],
[1, 0, 1, 1, 1, 1],
[1, 1, 0, 1, 1, 1],
[1, 1, 1, 0, 1, 1],
[1, 1, 1, 1, 0, 1],
[1, 1, 1, 1, 1, 0]
]