0

I have created a 3x3 np.array full of zeros with a = np.zeros((3,3)). I have another 3x1 numpy array b = np.array([[1],[2],[3]]) which values I want to set for the diagonal values in a. Hence I as result I want to have a matrix with the values of b on the diagonal and zeros everywhere else. I tried using the np.fill_diagonal() function with the following code:

a = np.zeros((3,3))
b = np.array([[1],[2],[3]])
print(np.fill_diagonal(a,b))

As result I get:

None

What I am doing wrong and how can I accomplish the above?

2Obe
  • 3,570
  • 6
  • 30
  • 54

0 Answers0