From b13ff51039c1f768d8d11760a6dbe032d953989f Mon Sep 17 00:00:00 2001 From: David Rotermund <54365609+davrot@users.noreply.github.com> Date: Fri, 15 Dec 2023 00:54:52 +0100 Subject: [PATCH] Update README.md Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com> --- numpy/ndarray/README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/numpy/ndarray/README.md b/numpy/ndarray/README.md index bed17fb..bf37d4c 100644 --- a/numpy/ndarray/README.md +++ b/numpy/ndarray/README.md @@ -151,7 +151,47 @@ Output: [3 4 5]] ``` +**WARNING!!! Don't confuse reshape with resize!** +## [numpy.ndarray.squeeze] + +```python +ndarray.squeeze(axis=None) +``` + +> Remove axes of length one from a. + +```python +import numpy as np + +A = np.zeros((4, 1, 1)) +print(A.shape) # -> (4, 1, 1) +A = A.squeeze() +print(A.shape) # -> (4,) + +A = np.zeros((4, 1, 9, 1)) # -> (4, 1, 9, 1) +print(A.shape) +B = A.squeeze(axis=1) # -> (4, 9, 1) +print(B.shape) +``` +## [numpy.moveaxis](https://numpy.org/doc/stable/reference/generated/numpy.moveaxis.html) + +```python +numpy.moveaxis(a, source, destination) +``` + +> Move axes of an array to new positions. +> +> Other axes remain in their original order. + +```python +import numpy as np + +A = np.zeros((4, 1, 9, 1)) +print(A.shape) # -> (4, 1, 9, 1) +B = np.moveaxis(A, 0, 1) +print(B.shape) # -> (1, 4, 9, 1) +``` ## [Array methods](https://numpy.org/doc/stable/reference/arrays.ndarray.html#array-methods)