[Numpy-discussion] Row-wise dot product?
Mon Sep 7 09:09:57 CDT 2009
> 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)
More information about the NumPy-Discussion