[Numpy-discussion] Padding An Array Along A Single Axis

Freddie Witherden freddie at witherden.org
Fri Jan 3 07:58:49 EST 2014

Hi all,

This should be an easy one but I can not come up with a good solution.
Given an ndarray with a shape of (..., X) I wish to zero-pad it to have
a shape of (..., X + K), presumably obtaining a new array in the process.

My best solution this far is to use

   np.zeros(curr.shape[:-1] + (curr.shape[-1] + K,))

followed by an assignment.  However, this seems needlessly cumbersome.
I looked at np.pad but it does not seem to provide a means of just
padding a single axis easily.

Regards, Freddie.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140103/b4ca76e8/attachment.sig>

More information about the NumPy-Discussion mailing list