Carsten Klein
Nov 6 · 1 min read

Hi Deny Rahmalianto,

It’s true the the code implementation does not resemble 1:1 the equation from the text. You can do this by writing:

wNew = np.mean(((signals * wg.T) - (wg_ * w.squeeze().reshape(m, 1))), axis=1)

Here you will first calculate the difference and then the mean. The result however is the same because it doesn't make a difference if you first calculate the mean and then multiply or you first multiply and then calculate the mean.

The example below might help:

x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
y = np.array([1, 2, 3])
print(np.mean(x * y.squeeze().reshape(3, 1), axis=1))
print(x.mean() * y)

    Carsten Klein

    Written by

    PhD in neuroscience interested in data analysis and artificial intelligence

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade