Skip to content

The problem of chapter A3.1 #198

@MaxforCherubim

Description

@MaxforCherubim

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions