torch.histogram#
- torch.histogram(input, bins, *, range=None, weight=None, density=False, out=None)#
計算張量中值的直方圖。
bins可以是整數或一維張量。如果
bins是一個整數,它指定了等寬的 bin 的數量。預設情況下,bin 的範圍的下限和上限由輸入張量的最小值和最大值確定。可以透過提供range引數來指定 bin 的範圍。如果
bins是一個一維張量,它指定了 bin 邊緣的序列,包括最右側的邊緣。它應該至少包含 2 個元素,並且其元素應該遞增。- 引數
input (Tensor) – 輸入張量。
bins – 整數或一維張量。如果為整數,則定義等寬 bin 的數量。如果為張量,則定義 bin 邊緣的序列,包括最右側的邊緣。
- 關鍵字引數
- 返回
包含直方圖值的 1D 張量。bin_edges(Tensor): 包含直方圖 bin 邊緣的 1D 張量。
- 返回型別
hist (張量)
示例
>>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.])) (tensor([ 0., 5., 2., 0.]), tensor([0., 0.75, 1.5, 2.25, 3.])) >>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]), density=True) (tensor([ 0., 0.9524, 0.3810, 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))