numpy extract 3d cubes from 3d array
<p>I would like to extract the 3D cubes (3x3x3) from a boolean 3D array of (180x180x197). This is similar to scipy.ndimage.measurements.label but need to fixed size of (3x3x3). 
Is there a fast way of doing this than using for loops. </p>

<p>Final solution with help from dnalow</p>

<pre><code>get_starting_point = numpy.vectorize(lambda sl: sl.start)
s = ndimage.generate_binary_structure(3,3)
result = []

while True:
    centers = ndimage.minimum_filter(b, 3, mode="constant")
    labels, num = ndimage.measurements.label(centers, s)
    if not num:
        break
    locations = ndimage.measurements.find_objects(labels)
    sp = get_starting_point(locations)
    for p in sp:
        if numpy.all(a[p[0]-1:p[0]+2, p[1]-1:p[1]+2, p[2]-1:p[2]+2]):
            result.append(p) 
        b[p[0]-1:p[0]+2, p[1]-1:p[1]+2, p[2]-1:p[2]+2] = False

numiter = len(result)
results = numpy.vstack(result)
</code></pre>

python numpy multidimensional-array scipy