[Numpy-discussion] matrix operation

2010-03-12 Thread gerardo.berbeglia
Hello, I want to divide an n x n (2-dimension) numpy array matrix A by a n (1-dimension) array d as follows: Take n = 2. Let A= 2 3 1 10 and let d = [ 3 2 ] Then i would like to have A/d = 2/3 3/3 1/2 10/2 This is to avoid loops to

[Numpy-discussion] matrix division without a loop

2010-03-12 Thread gerardo.berbeglia
Hello, I want to divide an n x n (2-dimension) numpy array matrix A by a n (1-dimension) array d as follows: Take n = 2. Let A= 2 3 1 10 and let d = [ 3 2 ] Then i would like to have A/d = 2/3 3/3 1/2 10/2 This is to avoid loops to

Re: [Numpy-discussion] matrix operation

2010-03-12 Thread Robert Kern
On Fri, Mar 12, 2010 at 12:52, gerardo.berbeglia gberbeg...@gmail.com wrote: Hello, I want to divide an n x n (2-dimension) numpy array matrix A by a n (1-dimension) array d as follows: Take n = 2. Let A=   2 3           1 10 and let d = [ 3 2 ] Then i would like to have A/d = 2/3  3/3

Re: [Numpy-discussion] matrix division without a loop

2010-03-12 Thread Friedrich Romstedt
import numpy A = numpy.asarray([[2, 3], [1, 10]]) print A [[ 2 3] [ 1 10]] d = numpy.asarray([3, 2]) print d [3 2] print (A.T * (1.0 / d)).T [[ 0.6667 1.] [ 0.5 5.]] - or - d = numpy.asarray([3.0, 2.0]) print d [ 3. 2.] print (A.T / d).T [[ 0.6667

Re: [Numpy-discussion] matrix division without a loop

2010-03-12 Thread Anne Archibald
On 12 March 2010 13:54, gerardo.berbeglia gberbeg...@gmail.com wrote: Hello, I want to divide an n x n (2-dimension) numpy array matrix A by a n (1-dimension) array d as follows: Look up broadcasting in the numpy docs. The short version is this: operations like division act elementwise on