0

Suppose i have

a = np.arange(9).reshape((3,3))

and i want to divide each row with a vector

n = np.array([1.1,2.2,3.3])

I tried the proposed solution in this question but the fractional value is not taken into account.

Community
  • 1
  • 1
Jasper Bernales
  • 1,601
  • 1
  • 11
  • 16

1 Answers1

0

I understand your question differently from the comments above:

import numpy as np 
a = np.arange(12).reshape((4,3))
print a

n = np.array([[1.1,2.2,3.3]])
print n

print a/n

Output:

[[ 0  1  2]
 [ 3  4  5]
 [ 6  7  8]
 [ 9 10 11]]
[[ 1.1  2.2  3.3]]
[[ 0.          0.45454545  0.60606061]
 [ 2.72727273  1.81818182  1.51515152]
 [ 5.45454545  3.18181818  2.42424242]
 [ 8.18181818  4.54545455  3.33333333]]

I also changed from a symmetric matrix (3x3) to (3x4) to point out that row vs columns matter. Also the divisor is a column vector now (double brackets).

roadrunner66
  • 7,772
  • 4
  • 32
  • 38