<div dir="ltr"><div>You might do better using scipy.spatial. It has very useful data structures for handling spatial coordinates. I am not exactly sure how to use them for this specific problem (not a domain expert), but I would imagine that the QHull wrappers there might give you some useful tools.<br><br></div>Ben Root<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 5, 2016 at 12:48 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">The idea is that I want to thin a large 2D buffer of x,y,z points to a given<br>
resolution by dividing the data into equal sized "cubes" (i.e. resolution is<br>
number of cubes along each axis) and averaging the points inside each cube<br>
(if any).<br>
<br>
<br>
*    # Fill up buffer data for demonstration purposes with initial buffer of<br>
size 10,000,000 to reduce to 1,000,000<br>
    size = 10000000<br>
    buffer = np.ndarray(shape=(size,3), dtype=np.float)<br>
    # fill it up<br>
    buffer[:, 0] = np.random.ranf(size)<br>
    buffer[:, 1] = np.random.ranf(size)<br>
    buffer[:, 2] = np.random.ranf(size)<br>
<br>
    # Create result buffer to size of cubed resolution (i.e. 100 ^ 3 =<br>
1,000,000)<br>
    resolution = 100<br>
    thinned_buffer = np.ndarray(shape=(resolution ** 3,3), dtype=np.float)<br>
<br>
    # Trying to convert the following into C to speed it up<br>
    x_buffer = buffer[:, 0]<br>
    y_buffer = buffer[:, 1]<br>
    z_buffer = buffer[:, 2]<br>
    min_x = x_buffer.min()<br>
    max_x = x_buffer.max()<br>
    min_y = y_buffer.min()<br>
    max_y = y_buffer.max()<br>
    min_z = z_buffer.min()<br>
    max_z = z_buffer.max()<br>
    z_block = (max_z - min_z) / resolution<br>
    x_block = (max_x - min_x) / resolution<br>
    y_block = (max_y - min_y) / resolution<br>
<br>
    current_idx = 0<br>
    x_idx = min_x<br>
    while x_idx < max_x:<br>
        y_idx = min_y<br>
        while y_idx < max_y:<br>
            z_idx = min_z<br>
            while z_idx < max_z:<br>
                inside_block_points = np.where((x_buffer >= x_idx) &<br>
                                                             (x_buffer <=<br>
x_idx + x_block) &<br>
                                                             (y_buffer >=<br>
y_idx) &<br>
                                                             (y_buffer <=<br>
y_idx + y_block) &<br>
                                                             (z_buffer >=<br>
z_idx) &<br>
                                                             (z_buffer <=<br>
z_idx + z_block))<br>
                if inside_block_points[0].size > 0:<br>
                    mean_point = buffer[inside_block_points[0]].mean(axis=0)<br>
                    thinned_buffer[current_idx] = mean_point<br>
                    current_idx += 1<br>
                z_idx += z_block<br>
            y_idx += y_block<br>
        x_idx += x_block<br>
    return thin_buffer<br>
*<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-tp42710p42726.html" rel="noreferrer" target="_blank">http://numpy-discussion.10968.n7.nabble.com/Multidimension-array-access-in-C-via-Python-API-tp42710p42726.html</a><br>
<div class="HOEnZb"><div class="h5">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">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>