Numpy Boolean Indexing: Show False Values

test_1 = taxi[:4, :4]
print(test_1.shape)
test_bool = [True, True, False, False]
test_bool_results = test_1[:, test_bool]
print(test_bool_results.shape)
test_bool_rows = test_1[test_bool, :]

If the Boolean Indexing allows you to pull the True values automatically; Is there a simple way to pull the False values also?

Invert the boolean indexer with ~ to get False values. If you want both False and True at the same time, that is basically not indexing at all.

How does it look when you use ~?

training_set = df[training_data_mask]
testing_set = df[~training_data_mask]

1 Like

It does not seem to work.

I saw it somewhere online as:

import numpy as np
a = np.array([[1,2,3], [4,5,6], [7,8,9]])

b = [True,False,True]

c = (~a[b])

print(c)

but then I tried that… hence the edit :slight_smile:

I got this…

[[ -2 -3 -4]
[ -8 -9 -10]]