fork download
  1. import numpy as np
  2. start = np.array([0,5,10,15,25,30,35,40,30,20,15,10])
  3. view = np.lib.stride_tricks.as_strided(start, shape=(start.size - 4, 5), strides=start.strides * 2, writeable=False)
  4. move = ((start[:-4] == view.min(axis=1)).astype(int) - (start[:-4] == view.max(axis=1)))
  5. print(move)
  6.  
  7. # For fun
  8. print(view)
Success #stdin #stdout 0.09s 25040KB
stdin
Standard input is empty
stdout
[ 1  1  1  1  1  0  0 -1]
[[ 0  5 10 15 25]
 [ 5 10 15 25 30]
 [10 15 25 30 35]
 [15 25 30 35 40]
 [25 30 35 40 30]
 [30 35 40 30 20]
 [35 40 30 20 15]
 [40 30 20 15 10]]