On 12 March 2010 13:54, gerardo.berbeglia 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 arrays of the
>>> 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
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 i