Binning of data along one axis in numpy : <p>I have a large two dimensional array <code>arr</code> which I would like to bin over the second axis using numpy. Because <code>np.histogram</code> flattens the array I'm currently using a for loop:</p>

<pre><code>import numpy as np

arr = np.random.randn(100, 100)

nbins = 10
binned = np.empty((arr.shape[0], nbins))

for i in range(arr.shape[0]):
    binned[i,:] = np.histogram(arr[i,:], bins=nbins)[0]
</code></pre>

<p>I feel like there should be a more direct and more efficient way to do that within numpy but I failed to find one.</p>
