[Numpy-discussion] Using interpolate with zero-rank array raises error

Ralf Gommers ralf.gommers@googlemail....
Thu Jul 16 22:37:58 CDT 2009


On Thu, Jul 16, 2009 at 12:07 PM, Tony Yu <tsyu80@gmail.com> wrote:

> Sorry, I don't know if its proper mailing-list-etiquette to bump my
> own post...


I don't  see a problem as long as you wait at least a few days before
bumping (which you did).

>
>
> Are there any comments on whether this interp error is expected
> behavior?


It seems to me that there are quite a few other functions that will give
errors with 0-D arrays (apply_along/over_axis are two that come to mind).
There is nothing to interpolate so I'm not surprised. Unless there is a
policy in Numpy that all funcs should work with 0-D arrays I would expect
that it's up to the user to not do things with them they're not intended
for.

Disclaimer: i don't know much about the reasons for 0-D arrays existing,
just what I learned from http://projects.scipy.org/numpy/wiki/ZeroRankArray

Cheers,
Ralf


>
> Thanks,
> -Tony
>
> > Date: Mon, 13 Jul 2009 13:50:50 -0400
> > From: Tony Yu <tsyu80@gmail.com>
> > Subject: [Numpy-discussion] Using interpolate with zero-rank array
> >       raises  error
> > To: Discussion of Numerical Python <numpy-discussion@scipy.org>
> > Message-ID: <67526143-4424-4E06-BFE5-435091C78878@gmail.com>
> > Content-Type: text/plain; charset="us-ascii"
> >
> > (Sorry if this is a duplicate; I think sent this from the wrong email
> > the first time)
> >
> > When using interpolate with a zero-rank array, I get "ValueError:
> > object of too small depth for desired array". The following code
> > reproduces this issue
> >
> >>>> import numpy as np
> >>>> x0 = np.array(0.1)
> >>>> x = np.linspace(0, 1)
> >>>> y = np.linspace(0, 1)
> >>>> np.interp(x0, x, y)
> >
> > I hesitate to call this behavior a bug (when I've done this in the
> > past, I find out I'm just doing something wrong), but I find the error
> > unnecessary (and the error output a bit obscure).
> >
> > Below is a (poorly tested) fix, which seems to work for me. (Sorry I'm
> > not on svn, so it isn't a proper diff)
> >
> > Cheers,
> > -Tony
> >
> > Python 2.5.1
> > numpy 1.3.0
> >
> > numpy/lib/function_base.py: line 1144
> > =============================
> >    if isinstance(x, (float, int, number)):
> >        return compiled_interp([x], xp, fp, left, right).item()
> > +    elif isinstance(x, np.ndarray) and x.ndim == 0:
> > +        return compiled_interp(x[np.newaxis], xp, fp, left, right)[0]
> >    else:
> >        return compiled_interp(x, xp, fp, left, right)
> > =============================
> >
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090716/8a94245a/attachment.html 


More information about the NumPy-Discussion mailing list