title: Apply a function to each dimension of a 4d array, returning an 4d array in python
body: <p>I load MNIST (test) dataset which is shaped as (10000, 28, 28, 1) (which mean 10000 images (grayscale 28x28 image)). I want to apply motion blur kernel on each of the images and get the output of also the same shape (10000, 28, 28, 1).
  I tried with def, vectorize but it doesn't work as I expected.</p>
  
  <p>It's running on python 3.6</p>
  
  <pre class="lang-py prettyprint-override"><code>x_test.shape
  --&gt; (numpy.ndarray) (10000, 28, 28, 1)
  
  
  def blurize(x):
      # kernel
      k = np.array([[0,0,0,0,0,0,0.0013],
      [0,0,0,0.0086,0.0574,0.1061,0.1165],
      [0,0.0450,0.0938,0.1426,0.0938,0.0450,0],
      [0.1165,0.1061,0.0574,0.0086,0,0,0],
      [0.0013,0,0,0,0,0,0]])
      return (ndimage.convolve(x.reshape(28,28), k, mode='constant', cval=0.0))
  
  blurred = blurize(x_test)
  plt.imshow(blurred[1], interpolation='none', cmap='gray')
  plt.show()
  
  </code></pre>
  
  <p>Result:</p>
  
  <pre class="lang-py prettyprint-override"><code>ValueError: cannot reshape array of size 7840000 into shape (28,28)
  </code></pre>
  
  <p>If I tried with 
  <code>blurred = blurize(x_test[1]).</code> it works but only for the second image. Since I don't want to loop over the whole array by the x_test[i] and merge frames into the expected output array of (10000, 28, 28, 1) again.
  Thanks.</p>