From 64cfcb292f275639fb3241de1c8da144573604eb Mon Sep 17 00:00:00 2001 From: David Rotermund <54365609+davrot@users.noreply.github.com> Date: Thu, 14 Dec 2023 18:33:15 +0100 Subject: [PATCH] Update README.md Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com> --- numpy/advanced_indexing/README.md | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/numpy/advanced_indexing/README.md b/numpy/advanced_indexing/README.md index 325fd07..84cb0d7 100644 --- a/numpy/advanced_indexing/README.md +++ b/numpy/advanced_indexing/README.md @@ -193,3 +193,41 @@ idx_1 = np.ones((2, 3, 4), dtype=int) print(a[:, idx_0, idx_1].shape) # -> (10, 2, 3, 4, 40, 50) print(a[:, idx_0, :, idx_1].shape) # -> (2, 3, 4, 10, 30, 50) ``` + +## [numpy.ix_](https://numpy.org/doc/stable/reference/generated/numpy.ix_.html) + +{: .topic-optional} +This is an optional topic! + +```python +numpy.ix_(*args) +``` + +> Construct an open mesh from multiple sequences. +> +> This function takes N 1-D sequences and returns N outputs with N dimensions each, such that the shape is 1 in all but one dimension and the dimension with the non-unit shape value cycles through all N dimensions. + +```python +import numpy as np + +a = np.arange(0, 9).reshape(3, 3) +print(a) +print() +print(a[np.ix_([0, 1], [0, 1])]) +print() +print(a[np.ix_([0, 1], [0, 2])]) +``` + +Output: +```python +[[0 1 2] + [3 4 5] + [6 7 8]] + +[[0 1] + [3 4]] + +[[0 2] + [3 5]] +``` +