[SciPy-Dev] Ticket #995, All scipy.constants.constants functions "choke" on non-array sequence input

David Goldsmith d.l.goldsmith@gmail....
Thu Jun 17 17:36:04 CDT 2010


On Thu, Jun 17, 2010 at 1:17 PM, Skipper Seabold <jsseabold@gmail.com>wrote:

> On Thu, Jun 17, 2010 at 4:10 PM, Vincent Davis <vincent@vincentdavis.net>
> wrote:
> > On Thu, Jun 17, 2010 at 1:58 PM, Skipper Seabold <jsseabold@gmail.com>
> wrote:
> >> On Thu, Jun 17, 2010 at 3:52 PM, Vincent Davis <
> vincent@vincentdavis.net> wrote:
> >>>
> >>>
> >>> Sent from my iPhone
> >>>
> >>> On Jun 17, 2010, at 1:24 PM, Skipper Seabold <jsseabold@gmail.com>
> >>> wrote:
> >>>
> >>>> On Thu, Jun 17, 2010 at 3:23 PM, Vincent Davis <
> vincent@vincentdavis.net
> >>>> > wrote:
> >>>>> On Thu, Jun 17, 2010 at 1:18 PM, Vincent Davis <
> vincent@vincentdavis.net
> >>>>> > wrote:
> >>>>>> The problem is that for example C2F is
> >>>>>>
> >>>>>> def C2F(C):
> >>>>>>     return 1.8 * C + 32
> >>>>>> So array_like (list, tuple...) does not work.
> >>>>>>
> >>>>>> What is the preferred solution?
> >>>>>>
> >>>>>> 1, Change the docs to say "scalar or array" and return a warning
> >>>>>> if C
> >>>>>> is not a scalar or array
> >>>>>> 2, Ad the ability to handle all array_like.
> >>>>>>
> >>>>> def C2F(C):
> >>>>>     return np.add(np.multilpy(1.8, C), 32)
> >>>>>
> >>>>> I think that accepts array-like and scaler and returns the same
> >>>>
> >>>> Or just C = np.asarray(C)
> >>>>
> >>>> This is quite often what is done.
> >>> But if I start with a list I expect a list back.
> >>>
> >>
> >> I don't know of any functions that preserve list inputs.
> >>
> >> In [3]: np.multiply([1,2,3,4,5],[2,3,4,5,6])
> >> Out[3]: array([ 2,  6, 12, 20, 30])
> >
> > Your right, it preserves a scaler but not a list.
> > Ok then would you prefer it accepts array_likem or scaler and returns
> > a array or scaler?
> >
>
> You can just say accepts array_like and use asanyarray (point taken) I
> think.
>

Yes, we have the convention that "array_like" includes (single) scalars.

DG
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-dev/attachments/20100617/d3023d1a/attachment.html 


More information about the SciPy-Dev mailing list