From: <jor...@bo...> - 2006-05-24 18:41:05
|
This thread discusses one of the things highest on my wishlist for=20 numpy. I have attached my first attempt at a code that will create a=20 broadcastingfunction that will broadcast a function over arrays where=20 the last N indices are assumed to be for use by the function, N=3D2 would= =20 be used for matrices. It is implemented for Numeric. /J=F6rgen 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] =3D=3D b.shape[2] >> assert a.shape[0] =3D=3D b.shape[0] >> except AssertionError: >> print "incorrect input shapes" >> res =3D zeros( (a.shape[0], a.shape[1], a.shape[1]), dtype=3Dfloat= ) >> for i in range(a.shape[0]): >> res[i,...] =3D dot( a[i,...], b[i,...] ) >> return res >> >=20 > 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. >=20 > pau >=20 >=20 > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, securit= y? > Get stuff done quickly with pre-integrated technology to make your job=20 > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geron= imo > http://sel.as-us.falkag.net/sel?cmd=3Dk&kid=120709&bid&3057&dat=121642 > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion >=20 |