0

I have a big 2d bitewise array (0s and 1s only) and a small one (3x3).

I want to see where the big array matches the small one, i.e. i, j for which

big_array[i-1:i+2, j-1:j+2] == small_array

There could be more than one (i,j) that satisfies the condition. How do I do this without writing a double nested i, j loop?

1

1 Answer 1

2

I hope, this code is what you need:

import numpy as np

big_array = np.array(...)
small_array = np.array(...)

for (i, j), _ in np.ndenumerate(big_array[:-2, :-2]):
    if (big_array[i:i+3, j:j+3] == small_array).all():
        print (i, j)
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.