Even better :

import numarray
m = numarray.arange(16,shape=(4,4))
numarray.sum(m)
array([24, 28, 32, 36])
numarray.sum(axis=1)
array([ 6, 22, 38, 54])

Pierre

Kent Johnson a écrit :
Kent Johnson wrote:

Liam Clarke wrote:

There's a specific package for arrays
http://www.stsci.edu/resources/software_hardware/numarray

that implements array mathematics. I use it for pixel map manipulation
in pygame, so it's relatively fast.



Here is one way to do what you want using numarray:


Here is another way, probably more idiomatic and faster. (I'm just doodling with numarray so there may still be a better way to do this...)

 >>> import numarray
 >>> m=numarray.array(range(16),shape=(4,4))

 >>> numarray.add.reduce(m)
array([24, 28, 32, 36])

 >>> numarray.add.reduce(m, axis=1)
array([ 6, 22, 38, 54])

Kent



-- Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France

tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to