[Numpy-discussion] np.diag(np.dot(A, B))

2015-05-22 Thread Mathieu Blondel
Hi, I often need to compute the equivalent of np.diag(np.dot(A, B)). Computing np.dot(A, B) is highly inefficient if you only need the diagonal entries. Two more efficient ways of computing the same thing are np.sum(A * B.T, axis=1) and np.einsum(ij,ji-i, A, B). The first can allocate quite

Re: [Numpy-discussion] np.diag(np.dot(A, B))

2015-05-22 Thread David Cournapeau
On Fri, May 22, 2015 at 5:39 PM, Mathieu Blondel math...@mblondel.org wrote: Hi, I often need to compute the equivalent of np.diag(np.dot(A, B)). Computing np.dot(A, B) is highly inefficient if you only need the diagonal entries. Two more efficient ways of computing the same thing are

Re: [Numpy-discussion] np.diag(np.dot(A, B))

2015-05-22 Thread Mathieu Blondel
Right now I am using np.sum(A * B.T, axis=1) for dense data and I have implemented a Cython routine for sparse data. I haven't benched np.sum(A * B.T, axis=1) vs. np.einsum(ij,ji-i, A, B) yet since I am mostly interested in the sparse case right now. When A and B are C-style and Fortran-style,

Re: [Numpy-discussion] np.diag(np.dot(A, B))

2015-05-22 Thread Nadav Horesh
There was an idea on this list to provide a function the run multiple dot on several vectors/matrices. It seems to be a particular implementation of this proposed function. Nadav. On 22 May 2015 11:58, David Cournapeau courn...@gmail.com wrote: On Fri, May 22, 2015 at 5:39 PM, Mathieu

Re: [Numpy-discussion] np.diag(np.dot(A, B))

2015-05-22 Thread Daπid
On 22 May 2015 at 12:15, Mathieu Blondel math...@mblondel.org wrote: Right now I am using np.sum(A * B.T, axis=1) for dense data and I have implemented a Cython routine for sparse data. I haven't benched np.sum(A * B.T, axis=1) vs. np.einsum(ij,ji-i, A, B) yet since I am mostly interested in