title: Vectorizing operation on numpy array
body: <p>I have a numpy array containing many three-dimensional numpy arrays, where each of these sub-elements is a grayscale image.  I want to use numpy's <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.vectorize.html" rel="nofollow">vectorize</a> to apply an affine transformation to each image in the array.</p>
  
  <p>Here is a minimal example that reproduces the issue:</p>
  
  <pre><code>import cv2
  import numpy as np
  from functools import partial
  
  # create four blank images
  data = np.zeros((4, 1, 96, 96), dtype=np.uint8)
  
  M = np.array([[1, 0, 0], [0, 1, 0]], dtype=np.float32) # dummy affine transformation matrix
  size = (96, 96) # output image size
  </code></pre>
  
  <p>Now I want to pass each of the images in data to <a href="http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#warpaffine" rel="nofollow">cv2.warpAffine(src, M, dsize)</a>.  Before I vectorize it, I first create a partial function that binds M and dsize:</p>
  
  <pre><code>warpAffine = lambda M, size, img : cv2.warpAffine(img, M, size) # re-order function parameters
  partialWarpAffine = partial(warpAffine, M, size)
  
  vectorizedWarpAffine = np.vectorize(partialWarpAffine)
  print data[:, 0].shape # prints (4, 96, 96)
  vectorizedWarpAffine(data[:, 0])
  </code></pre>
  
  <p>But this outputs:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/usr/lib/python2.7/dist-packages/numpy/lib/function_base.py", line 1573, in __call__
      return self._vectorize_call(func=func, args=vargs)
    File "/usr/lib/python2.7/dist-packages/numpy/lib/function_base.py", line 1633, in _vectorize_call
      ufunc, otypes = self._get_ufunc_and_otypes(func=func, args=args)
    File "/usr/lib/python2.7/dist-packages/numpy/lib/function_base.py", line 1597, in _get_ufunc_and_otypes
      outputs = func(*inputs)
    File "&lt;stdin&gt;", line 1, in &lt;lambda&gt;
  TypeError: src is not a numpy array, neither a scalar
  </code></pre>
  
  <p>What am I doing wrong - why can't I vectorize an operation on numpy arrays?</p>