目前我使用以下代码创建了bin:
bin_volumes = [((i+1)**3 - i**3) * bin_width**3 *4 * np.pi/3 for i in range(num_bins)]
垃圾箱的格式:
[(0.0, 0.10000000000000001), (0.10000000000000001, 0.20000000000000001), (0.20000000000000001, 0.30000000000000004), (0.30000000000000004, 0.40000000000000002), (0.40000000000000002, 0.5), (0.5, 0.60000000000000009), (0.60000000000000009, 0.70000000000000007), (0.70000000000000007, 0.80000000000000004), (0.80000000000000004, 0.90000000000000002), (0.90000000000000002, 1.0), (1.0, 1.1000000000000001), (1.1000000000000001, 1.2000000000000002), (1.2000000000000002, 1.3), (1.3, 1.4000000000000001), (1.4000000000000001, 1.5), (1.5, 1.6000000000000001), (1.6000000000000001, 1.7000000000000002), (1.7000000000000002, 1.8), (1.8, 1.9000000000000001), (1.9000000000000001, 2.0), (2.0, 2.1000000000000001), (2.1000000000000001, 2.2000000000000002), (2.2000000000000002, 2.3000000000000003), (2.3000000000000003, 2.4000000000000004), (2.4000000000000004, 2.5), (2.5, 2.6000000000000001), (2.6000000000000001, 2.7000000000000002), (2.7000000000000002, 2.8000000000000003), (2.8000000000000003, 2.9000000000000004), (2.9000000000000004, 3.0), (3.0, 3.1000000000000001), (3.1000000000000001, 3.2000000000000002), (3.2000000000000002, 3.3000000000000003), (3.3000000000000003, 3.4000000000000004), (3.4000000000000004, 3.5), (3.5, 3.6000000000000001), (3.6000000000000001, 3.7000000000000002), (3.7000000000000002, 3.8000000000000003), (3.8000000000000003, 3.9000000000000004)
数据格式:
3.615
4.42745271008
2.55619101399
2.55619101399
2.55619101399
4.42745271008
3.615
2.55619101399
4.42745271008
5.71581687075
5.71581687075
3.615
2.55619101399
2.55619101399
2.55619101399
2.55619101399
2.55619101399
2.55619101399
我希望每次数据点适合bin的范围时添加一个,这样我就可以收集每个范围的“频率”,然后用它来创建图形。
创建数据的代码:
for b in range(2047):
for a in range(b+1,2048):
vector1 = (l[b][0],l[b][1],l[b][2])
vector2 = (l[a][0],l[a][1],l[a][2])
x = vector1
y = vector2
vector3 = list(np.array(x) - np.array(y))
dotProduct = reduce( operator.add, map( operator.mul, vector3, vector3))
dp = dotProduct**.5
data = dp
答案 0 :(得分:1)
这将创建一个元组列表,每个元组定义一个bin的边界:
bins = [(i*bin_width, (i+1)*bin_width) for i in range(num_bins)]
如果您有数据值列表,请执行以下操作:
data = [0.7, 2.8, 1.3]
然后你可以计算出每个箱子中有多少像这样:
[sum([(value >= low) and (value < high) for value in data]) for low, high in bins]