torch.histogramdd#
- torch.histogramdd(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor[])#
计算张量中值的多维直方图。
将一个 innermost dimension 大小为 N 的输入张量解释为 N 维点的集合。将每个点映射到一个 N 维的 bin 集合中,并返回每个 bin 中的点数(或总权重)。
input
必须是至少有 2 个维度的张量。如果 input 的 shape 是 (M, N),它的 M 行定义了 N 维空间中的一个点。如果 input 有三个或更多维度,除了最后一个维度之外的所有维度都会被展平。每个维度独立地与其自身的严格递增的 bin 边界序列相关联。可以通过传递 1D 张量序列来显式指定 bin 边界。或者,可以通过传递指定每个维度中等宽 bin 数量的整数序列来自动构建 bin 边界。
- 对于 input 中的每个 N 维点
- 它的每个坐标都会在与它所属维度相对应的 bin 边界之间独立地进行 binning
对应的维度
- binning 结果被组合起来以确定该点所属的 N 维 bin(如果有的话)
落入的
如果点落入某个 bin,则该 bin 的计数(或总权重)会增加
不落入任何 bin 的点不计入输出
bins
可以是 N 个 1D 张量的序列,N 个整数的序列,或单个整数。如果
bins
是 N 个 1D 张量的序列,它显式指定了 N 个 bin 边界序列。每个 1D 张量应包含一个至少有一个元素的严格递增序列。K 个 bin 边界的序列定义了 K-1 个 bin,显式指定了所有 bin 的左边界和右边界。每个 bin 都包含其左边界。只有最右边的 bin 包含其右边界。如果
bins
是 N 个整数的序列,它指定了每个维度中等宽 bin 的数量。默认情况下,每个维度中最左边和最右边的 bin 边界由输入张量在相应维度中的最小和最大元素确定。可以使用range
参数手动指定每个维度中最左边和最右边的 bin 边界。如果
bins
是一个整数,它指定了所有维度中等宽 bin 的数量。注意
另请参阅
torch.histogram()
,它专门计算 1D 直方图。虽然torch.histogramdd()
从input
的 shape 推断其 bin 和 binning 值的维度,但torch.histogram()
接受并展平任何 shape 的input
。- 参数
input (Tensor) – 输入张量。
bins – Tensor[]、int[] 或 int。如果为 Tensor[],则定义 bin 边界序列。如果为 int[],则定义每个维度中等宽 bin 的数量。如果为 int,则定义所有维度中等宽 bin 的数量。
- 关键字参数
- 返回
包含直方图值的 N 维张量。bin_edges(Tensor[]): 包含 bin 边界的 N 个 1D 张量序列。
- 返回类型
hist (Tensor)
示例
>>> torch.histogramdd(torch.tensor([[0., 1.], [1., 0.], [2., 0.], [2., 2.]]), bins=[3, 3], ... weight=torch.tensor([1., 2., 4., 8.])) torch.return_types.histogramdd( hist=tensor([[0., 1., 0.], [2., 0., 0.], [4., 0., 8.]]), bin_edges=(tensor([0.0000, 0.6667, 1.3333, 2.0000]), tensor([0.0000, 0.6667, 1.3333, 2.0000]))) >>> torch.histogramdd(torch.tensor([[0., 0.], [1., 1.], [2., 2.]]), bins=[2, 2], ... range=[0., 1., 0., 1.], density=True) torch.return_types.histogramdd( hist=tensor([[2., 0.], [0., 2.]]), bin_edges=(tensor([0.0000, 0.5000, 1.0000]), tensor([0.0000, 0.5000, 1.0000])))