[PYTHON] Invert numpy Boolean array in tilde

Invert numpy Boolean array with ~ (tilde)

>>> import numpy as np

>>> l1 = np.array([True, False, True])
>>> ~l1
array([False,  True, False])

>>> l2 = np.array([[[True], [False], [True]], [[False], [True], [False]], [[True], [True], [True]]])
>>> ~l2
array([[[False],
        [ True],
        [False]],

       [[ True],
        [False],
        [ True]],

       [[False],
        [False],
        [False]]])

Recommended Posts

Invert numpy Boolean array in tilde
where in numpy
NumPy array manipulation (3)
NumPy array manipulation (1)
Various ways to extract columns in a NumPy array
Axis specification in NumPy
Convert NumPy array "ndarray" to lilt in Python [tolist ()]
python numpy array calculation
Install numpy in Visual Studio 2019
Quicksort an array in Python 3
Empty multidimensional array in python
Imitated Python's Numpy in C #
Matrix multiplication in python numpy
Create a python numpy array
Multidimensional array calculation without Numpy
About Numpy array and asarray
Fixed an issue where numpy.memmap wouldn't fit in numpy array memory