<div dir="ltr">Eh. The order of the outputs will be different than your code, if that makes a difference.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 5, 2016 at 3:31 PM, Eric Moore <span dir="ltr"><<a href="mailto:ewm@redtetrahedron.org" target="_blank">ewm@redtetrahedron.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>def reduce_data(buffer, resolution):<br>    thinned_buffer = np.zeros((resolution**3, 3))<br><br>    min_xyz = buffer.min(axis=0)<br>    max_xyz = buffer.max(axis=0)<br>    delta_xyz = max_xyz - min_xyz<br><br>    inds_xyz = np.floor(resolution * (buffer - min_xyz) / delta_xyz).astype(int)<br><br>    # handle values right at the max<br>    inds_xyz[inds_xyz == resolution] -= 1<br><br>    # covert to linear indices so that we can use <a href="http://np.add.at" target="_blank">np.add.at</a><br>    inds_lin = inds_xyz[:,0]<br>    inds_lin += inds_xyz[:,1] * resolution<br>    inds_lin += inds_xyz[:,2] * resolution**2<br><br>    <a href="http://np.add.at" target="_blank">np.add.at</a>(thinned_buffer, inds_lin, buffer)<br>    counts = np.bincount(inds_lin, minlength=resolution**3)<br><br>    thinned_buffer[counts != 0, :] /= counts[counts != 0, None]<br>    return thinned_buffer<br><br><br></div>The bulk of the time is spent in <a href="http://np.add.at" target="_blank">np.add.at</a>, so just over 5 s here with your 1e7 to 1e6 example. <br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 5, 2016 at 2:09 PM, mpc <span dir="ltr"><<a href="mailto:matt.p.conte@gmail.com" target="_blank">matt.p.conte@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This wasn't intended to be a histogram, but you're right in that it would be<br>
much better if I can just go through each point once and bin the results,<br>
that makes more sense, thanks!<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://numpy-discussion.10968.n7.nabble.com/Multidimension-array-access-in-C-via-Python-API-tp42710p42733.html" rel="noreferrer" target="_blank">http://numpy-discussion.10968.n7.nabble.com/Multidimension-array-access-in-C-via-Python-API-tp42710p42733.html</a><br>
<div><div>Sent from the Numpy-discussion mailing list archive at Nabble.com.<br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org" target="_blank">NumPy-Discussion@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>