How to normalize numpy array by row?

I use this:
def data_norm(x):
mu = x.mean(1)
sigma = x.std(1)
return (x-mu)/sigma
but got error, how to deal with it

Do you mean

import numpy as np

def data_norm(x):
    mu = x.mean(axis=1, keepdims=True)
    sigma = x.std(axis=1, keepdims=True)
    return (x-mu)/sigma

Got it! I has been confused by ‘keepdims’

In my understanding, keepdims means that len(output.shape) equals to len(input_shape).

Thx XD
I need to learn more about it