0

What is the most efficient way to mask columns from a numpy array?

a = np.arange(12).reshape((3,4))
mask = [True False True False]

I'm looking for something like:

b = a[mask, axis=1]

which would give the output:

b = [[0, 2],[4, 6], [8, 10]]

I need this for a large array.

Thanks,

jyco
  • 53
  • 1
  • 5
  • 1
    Possible duplicate of [Select elements of numpy array via boolean mask array](https://stackoverflow.com/questions/19984102/select-elements-of-numpy-array-via-boolean-mask-array) – Mazdak Sep 01 '18 at 10:09
  • 3
    a short answer `b = a[:, mask]` – BugKiller Sep 01 '18 at 10:38

0 Answers0