Q:

Numpy: add row and column

How can I add one row and one column to a numpy array.  The array has the shape (480,639,3) and I want to have the shape (481,640,3).  The new row and column should filled with zeros, like this:
[43,42,40],         ...        [64,63,61], [0,0,0]
   ...              ...            ...     [0,0,0]
[29,29,29],         ...        [38,37,35], [0,0,0]
[0,0,0], [0,0,0]    ...                    [0,0,0]

To add a new column I'm doing this:
b = numpy.zeros((480,640,3), dtype = int)
b[:,:-1] = old_arry

But how I can add one row?  Have I to use a loop or exists a better way to do this?  

A:

You can use pad
>>> old = np.random.random_integers(0, 100, size=(480, 640))
>>> np.pad(old, pad_width=((0, 1), (0, 1)), mode='constant')
array([[ 66,  22,  51, ...,  18,  15,   0],
       [ 28,  12,  43, ...,   8,  38,   0],
       [ 55,  43,  89, ...,  67,  58,   0],
       ...,
       [ 17,  25, 100, ...,  12,  52,   0],
       [ 97,  59,  82, ...,  38,  97,   0],
       [  0,   0,   0, ...,   0,   0,   0]])
>>> np.pad(old, pad_width=((0, 1), (0, 1)), mode='constant').shape
(481, 641)
>>>

You can also write it as np.pad(old, ((0, 1), (0, 1)), mode='constant'), i.e. without the pad_width keyword.  To set a different value for the padded areas, see the constant_values parameter in the documentation.