Re: [Tutor] How to sum rows and columns of a matrix?

2005-02-02 Thread Pierre Barbier de Reuille
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_h

Re: [Tutor] How to sum rows and columns of a matrix?

2005-02-02 Thread Kent Johnson
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

Re: [Tutor] How to sum rows and columns of a matrix?

2005-02-02 Thread Kent Johnson
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: >>> import numarray Cr

Re: [Tutor] How to sum rows and columns of a matrix?

2005-01-31 Thread Orri Ganel
Gregor Lingl wrote: Hi all of you, I'm representing a 4x4 matrix as a 16-element list, e.g. m=range(16) first 4 elements first row, second four elements second row etc. I want to sum rows and columns like i-th row: sum(m[4*i:4*i+4]) and ith column: sum(m[i::4]) This seems to be slow because of the

Re: [Tutor] How to sum rows and columns of a matrix?

2005-01-31 Thread Liam Clarke
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. On Mon, 31 Jan 2005 19:09:59 +0100, Gregor Lingl <[EMAIL PROTECTED]> wrote: > Hi all of you

[Tutor] How to sum rows and columns of a matrix?

2005-01-31 Thread Gregor Lingl
Hi all of you, I'm representing a 4x4 matrix as a 16-element list, e.g. m=range(16) first 4 elements first row, second four elements second row etc. I want to sum rows and columns like i-th row: sum(m[4*i:4*i+4]) and ith column: sum(m[i::4]) This seems to be slow because of the formation of the sli