[SciPy-user] advice on inner product, element by element

Joseph Anderson J.Anderson at hull.ac.uk
Sun Jun 29 14:45:48 EDT 2008


Hello All,

I'm looking for advice on speeding up what looks to be a simple problem to me, but is illusive due to my numpy-naiveness. I'm attempting to evaluate the inner product of n-frames of a time varying signal with n-frames a time varying matrix. The code below does this using two approaches,  list comprehension and python's map function. Neither approach is particularly fast, which is problematic, as I'm usually needing to do this many times at once--bringing things to a grinding halt.

I'm expecting / hoping there is a much faster, fancy numpy way (clever indexing?) to do the trick. I'm considering having a go at the problem with weave.blitz or weave.inline, but this seems somewhat fussy for solving something that I expect is actually easy, but I'm just missing.

Thanks in advance for the help!



Example code:

# parms
cs = 4                          # number of channels
fs = 60 * 44100         # number of frames (a minute at sr = 44100)

# sigs
a = reshape(arange(fs * cs), (fs, cs))
b = reshape(arange(fs * cs * cs), (fs, cs, cs))

print "a = ", a                 # the 'signal'
print "b = ", b                 # the 'matrices'

print "list comp = ", array([inner(val_a, val_b) for val_a, val_b in zip(a, b)])

print "mapping = ", asarray(map(inner, a, b))






~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dr Joseph Anderson
Lecturer in Music

School of Arts and New Media
University of Hull, Scarborough Campus,
Scarborough, North Yorkshire, YO11 3AZ, UK

T: +44.(0)1723.357341 T: +44.(0)1723.357370 F: +44.(0)1723.350815
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 3348 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20080629/f5c05be3/attachment.bin>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20080629/f5c05be3/attachment.ksh>


More information about the SciPy-User mailing list