[Numpy-discussion] Dot product threading?

Jörgen Stenarson jorgen.stenarson at bostream.nu
Wed May 24 11:42:06 EDT 2006


This thread discusses one of the things highest on my wishlist for 
numpy. I have attached my first attempt at a code that will create a 
broadcastingfunction that will broadcast a function over arrays where 
the last N indices are assumed to be for use by the function, N=2 would 
be used for matrices. It is implemented for Numeric.


/Jörgen


Pau Gargallo skrev:
>> Pau, can you confirm that this is the same
>> as the routine you're interested in?
>>
>> def dot2(a,b):
>>     '''Returns dot product of last two dimensions of two 3-D arrays,
>>     threaded over first dimension.'''
>>     try:
>>         assert a.shape[1] == b.shape[2]
>>         assert a.shape[0] == b.shape[0]
>>     except AssertionError:
>>         print "incorrect input shapes"
>>     res = zeros( (a.shape[0], a.shape[1], a.shape[1]), dtype=float )
>>     for i in range(a.shape[0]):
>>         res[i,...] = dot( a[i,...], b[i,...] )
>>     return res
>>
> 
> yes, that is what I would like. I would like it even with more
> dimensions and with all the broadcasting rules ;-)
> These can probably be achieved by building actual 'arrays of matrices'
> (an array of matrix objects) and then using the ufunc machinery.
> But I think that a simple dot2 function (with an other name of course)
> will still very useful.
> 
> pau
> 
> 
> -------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job 
> easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=k&kid0709&bid&3057&dat1642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
> 

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: jsarray.py
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060524/257370a6/attachment-0001.ksh>


More information about the NumPy-Discussion mailing list