<p>我也遇到过类似的问题,你的<a href="https://stackoverflow.com/questions/42385746/is-there-any-binning-function-that-returns-the-binned-matrix-instead-of-the-bi#comment71926005_42387068">last comment</a>似乎也有关系。在</p>
<p>假设三维空间中的点具有<code>x</code>、<code>y</code>和<code>z</code>,我想把所有值<code>z</code>分别放在它们的<code>x</code>和{<cd2>}的一个bin中。<a href="https://stackoverflow.com/a/6163403/4791226">This answer</a>使用<code>np.digitize</code>,对一维数组有效,但可以调整以适应三维。在</p>
<pre><code>In [1]: import numpy as np
In [2]: data = np.random.randint(0, 100, 3000).reshape(-1, 3)
In [3]: data
Out[3]:
array([[59, 94, 85],
[97, 47, 71],
[27, 10, 23],
...,
[48, 61, 87],
[72, 22, 86],
[80, 47, 45]])
In [4]: bins = np.linspace(0, 100, 10)
In [5]: bins
Out[5]:
array([ 0. , 11.11111111, 22.22222222, 33.33333333,
44.44444444, 55.55555556, 66.66666667, 77.77777778,
88.88888889, 100. ])
In [6]: digitized = np.digitize(data[:, 0:2], bins)
In [7]: digitized
Out[7]:
array([[6, 9],
[9, 5],
[3, 1],
...,
[5, 6],
[7, 2],
[8, 5]])
In [8]: data[np.equal(digitized, [6, 9]).all(axis=1)]
Out[8]:
array([[59, 94, 85],
[56, 94, 80],
[63, 97, 73],
[64, 94, 13],
[58, 92, 29],
[60, 97, 53],
[65, 92, 95],
[64, 91, 40],
[59, 92, 93],
[58, 94, 77],
[58, 89, 66],
[60, 89, 19],
[65, 95, 13],
[65, 89, 39]])
In [9]: data[np.equal(digitized, [6, 9]).all(axis=1)][:, 2]
Out[9]: array([85, 80, 73, 13, 29, 53, 95, 40, 93, 77, 66, 19, 13, 39])
</code></pre>
<p>要解决您的问题,请使用<code>data[np.equal(digitized, [index_latitide, index_longitude]).all(axis=1)[:, 2]</code>。这将检索所有的NO<sub>2</sub>值,尽管每个bin可以得到15个以上的值。在</p>