[Numpy-discussion] matrix division without a loop

Friedrich Romstedt friedrichromstedt@gmail....
Fri Mar 12 14:46:41 CST 2010


>>> 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.66666667  1.        ]
 [ 0.5         5.        ]]

- or -

>>> d = numpy.asarray([3.0, 2.0])
>>> print d
[ 3.  2.]
>>> print (A.T / d).T
[[ 0.66666667  1.        ]
 [ 0.5         5.        ]]

Friedrich


More information about the NumPy-Discussion mailing list