pydata-book icon indicating copy to clipboard operation
pydata-book copied to clipboard

The problem of chapter A3.1

Open MaxforCherubim opened this issue 10 months ago • 0 comments

The trick can not work:

def demean_axis(arr, axis):

    means = arr.mean(axis)
    indexer = [slice(None)] * arr.ndim
    indexer[axis] = np.newaxis
    
    return arr - means[indexer]

Here is the way to figue out:

def demean_axis(arr, axis):

    means = arr.mean(axis)
    indexer = [slice(None)] * arr.ndim
    indexer[axis] = np.newaxis
    
    return arr - means[*indexer]

MaxforCherubim avatar Apr 17 '24 16:04 MaxforCherubim