numpy.histogramdd#
- numpy.histogramdd(sample, bins=10, range=None, density=None, weights=None)[source]#
计算数据的多维直方图。
- 参数:
- sample(N, D) array, or (N, D) array_like
用于计算直方图的数据。
注意当输入为 array_like 时 sample 的特殊解释
当为数组时,每一行是一个 D 维空间中的坐标 - 例如
histogramdd(np.array([p1, p2, p3]))。当为 array_like 时,每个元素是单个坐标的值列表 - 例如
histogramdd((X, Y, Z))。
首选第一种形式。
- binssequence or int, optional
分箱规范
描述沿每个维度的单调递增的箱边的一系列数组。
每个维度的分箱数(nx, ny, … = bins)
所有维度的分箱数(nx=ny=…=bins)。
- rangesequence, optional
长度为 D 的序列,每个元素是一个可选的 (lower, upper) 元组,给出当箱边未在 bins 中显式给出时使用的外层箱边。序列中的 None 条目将导致使用相应维度的最小值和最大值。默认值 None 等价于传递一个 D 个 None 值的元组。
- densitybool,可选
如果为 False (默认值),返回每个箱中的样本数。如果为 True,返回箱中的概率密度函数,即
bin_count / sample_count / bin_volume。- weights(N,) array_like, optional
一个值数组 w_i,用于加权每个样本 (x_i, y_i, z_i, …)。如果 density 为 True,则权重将归一化为 1。如果 density 为 False,则返回的直方图的值等于属于落入每个箱的样本的权重的总和。
- 返回:
- Hndarray
sample x 的多维直方图。有关不同的可能语义,请参见 density 和 weights。
- edgestuple of ndarrays
一个元组,包含 D 个数组,描述每个维度的箱边。
另请参阅
histogram1-D 直方图
histogram2d2-D 直方图
示例
>>> import numpy as np >>> rng = np.random.default_rng() >>> r = rng.normal(size=(100,3)) >>> H, edges = np.histogramdd(r, bins = (5, 8, 4)) >>> H.shape, edges[0].size, edges[1].size, edges[2].size ((5, 8, 4), 6, 9, 5)