Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added and fixed demean_axis in appa #178

Open
wants to merge 1 commit into
base: 3rd-edition
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions appa.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,22 @@
"demeaned.mean(2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def demean_axis(arr, axis=0):\n",
" means = arr.mean(axis)\n",
"\n",
" # This generalizes things like [:, :, np.newaxis] to N dimensions\n",
" indexer = [slice(None)] * arr.ndim\n",
" indexer[axis] = np.newaxis\n",
" #Tuple is added in the next line to avoid non-tuple sequence for multidimensional indexing error\n",
" return arr - means[tuple(indexer)]"
]
},
{
"cell_type": "code",
"execution_count": 36,
Expand Down Expand Up @@ -939,9 +955,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.10.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
}