title: Can numpy einsum() perform a cross-product between segments of a trajectory
body: <p>I perform the cross product of contiguous segments of a trajectory (xy coordinates) using the following script:</p>
  
  <pre><code>In [129]:
  def func1(xy, s):
      size = xy.shape[0]-2*s
      out = np.zeros(size)
      for i in range(size):
          p1, p2 = xy[i], xy[i+s]     #segment 1
          p3, p4 = xy[i+s], xy[i+2*s] #segment 2
         out[i] = np.cross(p1-p2, p4-p3)
      return out
  
  def func2(xy, s):
      size = xy.shape[0]-2*s
      p1 = xy[0:size]
      p2 = xy[s:size+s]
      p3 = p2
      p4 = xy[2*s:size+2*s]
  
      tmp1 = p1-p2
      tmp2 = p4-p3
      return tmp1[:, 0] * tmp2[:, 1] - tmp2[:, 0] * tmp1[:, 1]
  
  
  In [136]:
  xy = np.array([[1,2],[2,3],[3,4],[5,6],[7,8],[2,4],[5,2],[9,9],[1,1]])
  func2(xy, 2)
  
  Out[136]:
  array([ 0, -3, 16,  1, 22])
  </code></pre>
  
  <p>func1 is particularly slow because of the inner loop so I rewrote the cross-product myself (func2) which is orders of magnitude faster.</p>
  
  <p>Is it possible to use the numpy einsum function to make the same calculation?</p>