0

I have two numpy arrays of even size. One is the pixel values and another one is a "mask", where I have True or False, meaning if this is part of the cut out image or just "filled" up image to get an even size. So for example, if this is one column of the mask:

array([False, False, False, False, False, False, False, False, False,
       False, False, False, False, False, False, False, False, False,
       False, False, False, False, False, False, False, False, False,
       False, False, False, False, False, False, False, False, False,
       False, False, False, False, False, False, False, False, False,
       False, False, False, False, False, False, False, False, False,
       False, False, False, False, False, False, False, False, False,
       False, False, False, False,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
       False, False, False, False], dtype=bool)

Now I would like to (column by column) read out only the image values when there is a True in the mask array.

What is the best way to do this?

Thanks :)

(using python3 btw)

2
  • 4
    NumPy supports boolean indexing, so if I've understood your question you should just be able to write something like pixels[mask]. Commented Apr 20, 2016 at 20:30
  • Exactly what I was looking for! Thanks! Commented Apr 21, 2016 at 13:08

1 Answer 1

1

I think the function you're looking for is numpy.where. This will give you an array of indices where a condition is True.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.