3

I'm stuck with the problem of testing whether or not a 2d array appears in the exact same order in another 2d array, e.g.:

01
23

in

000100
002300
000000
000000

would return true, but in

001000
002300
000000
000000

would return false.

I've already attempted to use scipy.signal.correlate2d but to no avail. Any help? Cheers!

)edit) Code for generating the data:

import numpy as np
a = np.array([[0,0,0,1,0,0],
             [0,0,2,3,0,0],
             [0,0,0,0,0,0],
             [0,0,0,0,0,0]])

a = np.array([[0,0,1,0,0,0],
             [0,0,2,3,0,0],
             [0,0,0,0,0,0],
             [0,0,0,0,0,0]])



b = np.array([[0,1],
             [2,3]])
2
  • 1
    can you add the array constructors to your question? and the exact command you tried Commented Mar 15, 2022 at 9:14
  • I've added the constructors. Any ideas on how to proceed? Commented Mar 15, 2022 at 9:28

1 Answer 1

2
from skimage.util import view_as_windows

windows = view_as_windows(a, b.shape)

print((windows == b).all(axis=(2,3)).any())

would be the answer, as stated in How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?

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.