pytorch中的数学函数
torch.histc():指定最小值最大值和bin数,对tensor中的数据进行区段统计。
a = torch.rand(2,2)*10
print(a)
#6表示取6个区间段,0,0,表示采用Tensor中的最大值和最小值,也可以自己更改区间上的最大值和最小值
print( torch.histc(a,6, 0, 0) )
运行结果如下:
tensor([[5.5695, 1.2099],
[1.3061, 1.0443]]) #a的值
tensor([3., 0., 0., 0., 0., 1.]) #6个区间段中数据的的统计
注:torch.bincount()只支持一维的Tensor
a = torch.randint(0, 10, [10]) #取0-10中间任意10个数
print(a)
print( to