> From: T J <tjhnson <at> gmail.com>
> Is there a better way to achieve the following, perhaps without the
> python for loop?
> 
> >>> x.shape
> (10000,3)
> >>> y.shape
> (10000,3)
> >>> z = empty(len(x))
> >>> for i in range(10000):
> ...    z[i] = dot(x[i], y[i])
> ...
> _______________________________________________

Nadav Horesh <nadavh <at> visionsense.com> writes:

> 
> (x*y).sum(1)
> 
>   Nadav
> 


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)

Best,
Hansres





_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to