[Numpy-discussion] Only integer scalar arrays can be converted to a scalar index
Juan Nunez-Iglesias
jni.soma at gmail.com
Fri Sep 15 23:39:10 EDT 2017
@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.kern at gmail.com>, wrote:
> On Sat, Sep 16, 2017 at 7:16 AM, Chris Barker - NOAA Federal <chris.barker at 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 at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20170916/ac7e9497/attachment.html>
More information about the NumPy-Discussion
mailing list