Mean subtraction of patches in python nympy scipy
Question: I have a numpy array of 3 dimension, it's a grid of patches of 8x8 images.

What is the best way to subtract from each patch it's average, in other words
each patch has a unique mean and I want to subtract it. I tried the following
with no success obviously because both arrays are not equal in shape

    
    
    patches=- patches.mean(axis = 2).mean(axis = 1)
    

I thought of using the repeat function, something like:

    
    
    patches=- np.repeat(np.repeat(patches.mean(axis =2).mean(axis =1).reshape((n_patches, 8, 8)), 1, 1))
    

Put I think that following this route would lead to an inefficient solution.
Any thoughts or solution on this?


Answer: 
    import numpy as np
    a = np.random.rand(10,8,8)
    mean = a.mean(axis=2).mean(axis=1)
    b = a - mean[:, np.newaxis, np.newaxis] # reshape the mean as (10, 1, 1)
    

