[Numpy-discussion] Is this a bug?

Nathaniel Smith njs at pobox.com
Tue Sep 16 16:26:41 EDT 2014


On Tue, Sep 16, 2014 at 3:55 PM,  <josef.pktd at gmail.com> wrote:
> On Tue, Sep 16, 2014 at 3:42 PM, Nathaniel Smith <njs at pobox.com> wrote:
>> On Tue, Sep 16, 2014 at 3:27 PM, Charles R Harris
>> <charlesr.harris at gmail.com> wrote:
>>> Hi All,
>>>
>>> It turns out that gufuncs will broadcast the last dimension if it is one.
>>> For instance, inner1d has signature `(n), (n) -> ()`, yet
>>>
>>> In [27]: inner1d([1,1,1], [1])
>>> Out[27]: 3
>>
>> Yes, this looks totally wrong to me too... broadcasting is a feature
>> of auto-vectorizing a core operation over a set of dimensions, it
>> shouldn't be applied to the dimensions of the core operation itself
>> like this.
>
> Are these functions doing any numerical shortcuts in this case?
>
> If yes, this would be convenient.
>
> inner1d(x, weights)   with weights is either (n, ) or ()
>
> if weights == 1:
>     return x.sum()
> else:
>     return inner1d(x, weights)

Yes, if this is the behaviour you want then I think you should write
this if statement :-). This case isn't general enough to build
directly into inner1d IMHO.

-n

-- 
Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org



More information about the NumPy-Discussion mailing list