我在N维中有一组M点,每个点都有一个相关的“权重”值(基本上是一个M浮点数数组)。利用numpy的直方图d(),可以生成集的N维直方图.
如果在weights中使用histogramdd()参数,则返回:
属于每个垃圾箱的样本的重量之和。
下面的代码显示了创建这些数组的热度:
import numpy as np
# N-dimensional M points.
N_dim, M = 3, 1000
points = np.random.uniform(0., 1., size=(M, N_dim))
# Weight for each point
weights = np.random.uniform(0., 1., M)
# N-dimensional histogram.
histo = np.histogramdd(points)[0]
# Histogram containing the sum of the weights in each bin.
weights_histo = np.histogramdd(points, weights=weights)[0]而不是这样,我需要为points创建N维直方图,其中存储在每个bin中的值是与该bin内各点相关联的所有权重中的最大权重值。
我只需要存储在每个垃圾箱中的最大重量,而不是所有重量的总和。
我怎么能这么做?
发布于 2017-08-17 12:49:47
在binned_statistic中有几个scipy.stats函数。‘'max’是默认的统计信息之一,但是您也可以使用任何可调用的。
import numpy as np
from scipy.stats import binned_statistic_dd
# N-dimensional M points.
N_dim, M = 3, 1000
points = np.random.uniform(0., 1., size=(M, N_dim))
# Weight for each point
weights = np.random.uniform(0., 1., M)
weights_histo, bin_edges, bin_indices = binned_statistic_dd(points,
weights,
statistic=np.max,
bins=5)
print weights_histo.shape # (5,5,5)https://stackoverflow.com/questions/45680911
复制相似问题