How to apply the histogram function in pytorch to a specific axis?
I would like to use the torch.histc function to different samples in my training batch.
Here is an example:

&gt;&gt;&gt; tt2 = torch.from_numpy(np.array([[-0.2, 1, 0.21], [-0.1, 0.32, 0.2]]))
&gt;&gt;&gt; tt3 = torch.from_numpy(np.array([[-0.8, 0.6, 0.1], [-0.6, 0.5, 0.4]]))
&gt;&gt;&gt; t = torch.cat((tt2, tt3), 1)
&gt;&gt;&gt; t
tensor([[-0.2000,  1.0000,  0.2100, -0.8000,  0.6000,  0.1000],
        [-0.1000,  0.3200,  0.2000, -0.6000,  0.5000,  0.4000]],
       dtype=torch.float64)
&gt;&gt;&gt; torch.histc(t, bins=1, min=0, max=5)
tensor([8.], dtype=torch.float64)


However, I don't want to apply the histogram function for all the values in t, I rather expect something like this:

&gt;&gt;&gt; torch.histc(torch.tensor([[-0.2000,  1.0000,  0.2100, -0.8000,  0.6000,  0.1000]]), bins=1, min=0, max=5)
tensor([4.])
&gt;&gt;&gt; torch.histc(torch.tensor([[-0.1000,  0.3200,  0.2000, -0.6000,  0.5000,  0.4000]]), bins=1, min=0, max=5)
tensor([4.])
&gt;&gt;&gt;


And, finally, I want to aggregate all the histograms in the same tensor: tensor([[4.], [4.]]).
Thanks in advance

The problem is solved with this function, but I'm not sure this is the most pythonic way to do it:

import numpy as np

def funct(semembs_as, semembs_bs):
    t = torch.cat((semembs_as, semembs_bs), 1)
    # make prediction a value between 0.0 and 5.0
    l = [torch.histc(ti, bins=1, min=0, max=5) for ti in t]
    y = [list(e) for e in l]
    return torch.from_numpy(np.array(y))

t1 = torch.from_numpy(np.array([[-0.2, 1, 0.21], [-0.1, 0.32, 0.2]]))
t2 = torch.from_numpy(np.array([[0.7, 0.0, -0.6], [-0.6, 0.5, 0.4]]))

x = funct(t1, t2)
x



  tensor([[4.],
          [4.]], dtype=torch.float64)


If you have better solutions, don't hesitate to comment, please.
