From 835a42b07bbb9ada1228c15f4f7856c25f92d567 Mon Sep 17 00:00:00 2001 From: David Rotermund <54365609+davrot@users.noreply.github.com> Date: Thu, 14 Dec 2023 16:21:04 +0100 Subject: [PATCH] Update README.md Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com> --- numpy/bool_matrix/README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/numpy/bool_matrix/README.md b/numpy/bool_matrix/README.md index cef8a70..6b9a0b3 100644 --- a/numpy/bool_matrix/README.md +++ b/numpy/bool_matrix/README.md @@ -128,6 +128,32 @@ Output: (array([0, 1, 1, 1]), array([2, 0, 1, 2])) ``` +For reversing it, you can use this: + +```python +import numpy as np + +a = np.arange(0, 6).reshape((2, 3)) +a = (a > 1) +print(a) +idx = np.nonzero(a) +print() + +b = np.zeros((2, 3), dtype=bool) +b[idx] = True +print(b) +``` + +Output: + +```python +[[False False True] + [ True True True]] + +[[False False True] + [ True True True]] +``` + ## [Logic functions](https://numpy.org/doc/stable/reference/routines.logic.html) ### [Truth value testing](https://numpy.org/doc/stable/reference/routines.logic.html#truth-value-testing)