I have a 6D numpy array, say it has shape (N1,N2,N3,N4,NY,NX). It's holding many images, each separate image is held in the last 2 dimensions (NY,NX). The other dimensions are just a way to organise the images.
I have a function that takes an image and outputs an image of the same shape. It requires the full 2D image, i.e. it won't work if we break the image into 1D arrays.
Is there a numpy function for applying this function over the whole array, to return an array with the same shape (N1,N2,N3,N4,NY,NX)?
I can do it with python loops of course, but I was wondering if there's a numpy way which will be faster thanks to vectorisation?
numpy.apply_along_axis() almost does this but I don't think it can work with a function that requires 2D arrays, I think it always applies the function to 1D arrays.
Similarly numpy.apply_over_axes() seems close but the function doesn't take an axis parameter and numpy.apply_over_axes() always seems to want to pass this.
Thanks!