[Numpy-discussion] Row-wise dot product?
Mon Sep 7 11:07:32 CDT 2009
On Mon, Sep 7, 2009 at 10:09 AM, Hans-Andreas Engel<firstname.lastname@example.org> wrote:
>> From: T J <tjhnson <at> gmail.com>
>> Is there a better way to achieve the following, perhaps without the
>> python for loop?
>> >>> x.shape
>> >>> y.shape
>> >>> z = empty(len(x))
>> >>> for i in range(10000):
>> ... z[i] = dot(x[i], y[i])
> Nadav Horesh <nadavh <at> visionsense.com> writes:
> If you wish to avoid the extra memory allocation implied by `x*y'
> and get a ~4x speed-up, you can use a generalized ufunc
> (numpy >= 1.3, stolen from the testcases):
> z = numpy.core.umath_tests.inner1d(x, y)
Thanks for the example. There are not many examples of generalized
ufuncs on the mailing list and it's easy to forget that they have been added.
Initially, I didn't find them in my numpy 1.3.0 install (AttributeErrors).
It seems they have to be explicitly imported:
> NumPy-Discussion mailing list
More information about the NumPy-Discussion