fork download
  1. import numpy as np
  2.  
  3. def isin_seq(a,b):
  4. # Look for the presence of b in a, while keeping the sequence
  5. sidx = a.argsort()
  6. idx = np.searchsorted(a,b,sorter=sidx)
  7. idx[idx==len(a)] = 0
  8. ssidx = sidx[idx]
  9. return (np.diff(ssidx)==1).all() & (a[ssidx]==b).all()
  10.  
  11. haystack = np.array([1, 1, 2])
  12. needle = np.array([1, 2])
  13.  
  14. print(isin_seq(haystack, needle))
Success #stdin #stdout 0.19s 27236KB
stdin
Standard input is empty
stdout
False