[Numpy-discussion] np.insert with axis=-1

Félix Hartmann felix.hartmann at crans.org
Mon Jul 1 08:11:15 EDT 2013


Hi all,

I recently upgraded from Numpy 1.6.2 to 1.7.1 on my Debian testing, and
then got a bug in a program that was previously working. It turned out
that the problem comes from the np.insert function when the argument
`axis=-1` is given.

Here is a minimal example:
>>> u = np.zeros((2,3,4))
>>> ui = np.ones((2,3))
>>> u = np.insert(u, 1, ui, axis=-1)

The last line should be equivalent to 
>>> u = np.insert(u, 1, ui, axis=2)

It was indeed the case in Numpy 1.6, but in 1.7.1 it raises a
ValueError exception.

Note that the problem seems specific to axis=-1, and not to all negative
axis values, since the following example works as expected:
>>> u = np.zeros((2,3,4))
>>> ui = np.ones((2,4))
>>> u = np.insert(u, 1, ui, axis=-2)  # equivalent to axis=1

I didn't check on current master, so maybe things have changed since
1.7.1. If they have not, do you think a bug report would be relevant?

Cheers,
Félix



More information about the NumPy-Discussion mailing list