Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT</strong> The following code does allow to perform a convolution based check of equality. It maps <code>True</code> to <code>1</code> and <code>False</code> to <code>-1</code>. It also reverses <code>b</code>, which is needed for it to work properly:</p> <pre><code>def search(a, b) : return np.where(np.round(fftconvolve(a * 2 - 1, (b * 2 - 1)[::-1], mode='valid') - len(b)) == 0)[0] </code></pre> <p>I have checked that it gives the same output as the <code>as_strided</code> method for a variety of random inputs, which it does. I have also timed both approached, and convolution only starts paying off with largish search tokens of around 256 items.</p> <hr> <p>It seems like a little overkill, but with boolean data you can use (abuse?) convolution:</p> <pre><code>In [8]: np.where(np.convolve(may_a, may_b.astype(int), ...: mode='valid') == may_b.sum())[0] Out[8]: array([2, 7]) </code></pre> <p>For larger datasets it may be faster to go with <code>scipy.signal.fftconvolve</code>:</p> <pre><code>In [13]: np.where(scipy.signal.fftconvolve(may_a, may_b, ....: mode='valid') == may_b.sum())[0] Out[13]: array([2, 7]) </code></pre> <p>You have to be careful though, because the output now is floating point, and rounding may spoil the equality check:</p> <pre><code>In [14]: scipy.signal.fftconvolve(may_a, may_b, mode='valid') Out[14]: array([ 1., 1., 2., 1., 1., 1., 1., 2.]) </code></pre> <p>So you may be better off with something along the lines of:</p> <pre><code>In [15]: np.where(np.round(scipy.signal.fftconvolve(may_a, may_b, mode='valid') - ....: may_b.sum()) == 0)[0] Out[15]: array([2, 7]) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload