@Robert, good point, always good to try out code before speculating on a 
thread. ;)

Here’s working code to do the averaging, though it’s not block-wise, you’ll 
have to add that on top with dask/util.apply_parallel. Note also that because 
of the C-order of numpy arrays, it’s much more efficient to think of axis 0 as 
the “vertical” axis, rather than axis 2. See 
http://scikit-image.org/docs/dev/user_guide/numpy_images.html#notes-on-array-order
 for more info.

import numpy as np
from skimage import util

vol = np.linspace(1, 125, 125, dtype=np.int32).reshape(5, 5, 5)
window_shape = (1, 3, 3)
windows = util.view_as_windows(vol, window_shape)
print(windows.shape)  # (5, 3, 3, 1, 3, 3)
averaged = np.mean(windows, axis=(3, 4, 5))

HTH!

Juan.


On 16 Sep 2017, 12:34 PM +1000, Robert Kern <robert.k...@gmail.com>, wrote:
> On Sat, Sep 16, 2017 at 7:16 AM, Chris Barker - NOAA Federal 
> <chris.bar...@noaa.gov> wrote:
> >
> > No thoughts on optimizing memory, but that indexing error probably comes 
> > from np.mean producing float results. An astype call shoulder that work.
>
> Why? It's not being used as an index. It's being assigned into a float array.
>
> Rather, it's the slicing inside of `trace_block()` when it's being given 
> arrays as inputs for `x` and `y`. numpy simply doesn't support that because 
> in general the result wouldn't have a uniform shape.
>
> --
> Robert Kern
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion

Reply via email to