Re: [Numpy-discussion] simple reduction question

2014-12-24 Thread Charles R Harris
On Wed, Dec 24, 2014 at 10:29 AM, wrote: > > > On Wed, Dec 24, 2014 at 10:30 AM, Julian Taylor < > jtaylor.deb...@googlemail.com> wrote: > >> On 24.12.2014 16:25, Neal Becker wrote: >> > What would be the most efficient way to compute: >> > >> > c[j] = \sum_i (a[i] * b[i,j]) >> > >> > where a[i]

Re: [Numpy-discussion] simple reduction question

2014-12-24 Thread josef.pktd
On Wed, Dec 24, 2014 at 10:30 AM, Julian Taylor < jtaylor.deb...@googlemail.com> wrote: > On 24.12.2014 16:25, Neal Becker wrote: > > What would be the most efficient way to compute: > > > > c[j] = \sum_i (a[i] * b[i,j]) > > > > where a[i] is a 1-d vector, b[i,j] is a 2-d array? > > > > This seems

Re: [Numpy-discussion] simple reduction question

2014-12-24 Thread Neal Becker
Nathaniel Smith wrote: > On Wed, Dec 24, 2014 at 3:25 PM, Neal Becker wrote: >> What would be the most efficient way to compute: >> >> c[j] = \sum_i (a[i] * b[i,j]) >> >> where a[i] is a 1-d vector, b[i,j] is a 2-d array? > > I think this formula is just np.dot(a, b). Did you mean c = \sum_j > \

Re: [Numpy-discussion] simple reduction question

2014-12-24 Thread Nathaniel Smith
On Wed, Dec 24, 2014 at 3:25 PM, Neal Becker wrote: > What would be the most efficient way to compute: > > c[j] = \sum_i (a[i] * b[i,j]) > > where a[i] is a 1-d vector, b[i,j] is a 2-d array? I think this formula is just np.dot(a, b). Did you mean c = \sum_j \sum_i (a[i] * b[i, j])? > This seems

Re: [Numpy-discussion] simple reduction question

2014-12-24 Thread Julian Taylor
On 24.12.2014 16:25, Neal Becker wrote: > What would be the most efficient way to compute: > > c[j] = \sum_i (a[i] * b[i,j]) > > where a[i] is a 1-d vector, b[i,j] is a 2-d array? > > This seems to be one way: > > import numpy as np > a = np.arange (3) > b = np.arange (12).reshape (3,4) > c = n

[Numpy-discussion] simple reduction question

2014-12-24 Thread Neal Becker
What would be the most efficient way to compute: c[j] = \sum_i (a[i] * b[i,j]) where a[i] is a 1-d vector, b[i,j] is a 2-d array? This seems to be one way: import numpy as np a = np.arange (3) b = np.arange (12).reshape (3,4) c = np.dot (a, b).sum() but np.dot returns a vector, which then need