title: Array Padding Numpy
body: <p>I have the following matrix: </p>
  
  <pre><code>x = \
      np.array([[[[0.99256822,  0.63019905],
                  [0.77484078,  0.27471319]],
  
                 [[0.94722451,  0.95948516],
                  [0.81838252,  0.48979609]],
  
                 [[0.81673764,  0.9388614],
                  [0.57575844,  0.82265243]]],
  
  
                [[[0.95485566,  0.94870753],
                  [0.92680463,  0.90044481]],
  
                 [[0.90128127,  0.98683992],
                    [0.9115591,  0.85900321]],
  
                 [[0.949711,    0.85709163],
                    [0.70392261,  0.91043368]]]])
  </code></pre>
  
  <p>It has dimensions: <code>2,3,2,2</code>. What I want to do is multiply it with the following matrix: </p>
  
  <pre><code>y = \
      np.array([[[[ 0.,          0.,          0.63019905,  0.        ],
     [ 0.,          0.99256822,  0.,          0.        ],
     [ 0.77484078,  0.,          0.,          0.27471319],
     [ 0.,          0.,          0.,          0.        ]],
    [[ 0.,          0.,          0.,          0.        ],
     [ 0.94722451,  0.,          0.,          0.95948516],
     [ 0.81838252, 0.,          0.,          0.        ],
     [ 0.,          0.,          0.48979609,  0.        ]],
  
    [[ 0.,          0.,          0.,          0.        ],
     [ 0.,          0.81673764,  0.,          0.9388614 ],
     [ 0.,          0.,          0.,          0.82265243],
     [ 0.57575844,  0.,          0.,          0.        ]]],
   [[[ 0.,          0.95485566,  0.,          0.        ],
     [ 0.,          0.,          0.,          0.94870753],
     [ 0.,          0.92680463,  0.,          0.        ],
     [ 0.,          0.,          0.,          0.90044481]],
  
    [[ 0.,          0.90128127,  0.,          0.        ],
     [ 0.,          0.,          0.,          0.98683992],
     [ 0.,          0.9115591,   0.,          0.        ],
     [ 0.,          0.,          0.,          0.85900321]],
  
    [[ 0.,          0.,          0.,          0.85709163],
     [ 0.,          0.949711,    0.,          0.        ],
     [ 0.,          0.70392261,  0.,          0.91043368],
     [ 0.,          0.,          0.,          0.        ]]]])
  </code></pre>
  
  <p>This has dimensions <code>2,3,4,4</code>. So what I need to do is to pad the first matrix in such a way that we have each entry copied 4 times, so that the multiplication can take place (3 of the results will elaborate to 0, and the final result will be the multiplication I want). Therefore, I need to convert the first matrix into something that looks like this: </p>
  
  <pre><code>    [[[[ 0.99256822          0.99256822          0.63019905  0.63019905        ]
         [ 0.99256822          0.99256822          0.63019905  0.63019905        ]
          [ 0.77484078         0.77484078          0.27471319  0.27471319]
          [ 0.77484078         0.77484078          0.27471319  0.27471319        ]]
  </code></pre>
  
  <p>and so on...</p>
  
  <p>Update: </p>
  
  <pre><code> def bprop(self, inputs, outputs, grads_wrt_outputs):
  
          m,n = grads_wrt_outputs.shape[:2]
          o = inputs.shape[2]
          p = inputs.shape[3]
          return (self.mask.reshape(m,n,2,2,2,2)*grads_wrt_outputs[:,:,:,None,:,None]).reshape(m,n,o,p) 
  </code></pre>
  
  <p>This is the scenario I am using this in. </p>