If I want to create a 5x5 zero matrix with values of 10, 20, 30, 40 just above the diagonal I can do the following:
import numpy as np
np.diag((1+np.arange(4))*10,k=1)
but how can i replace the elements above the diagonal in a 5x5 random matrix with the same array 10, 20, 30, 40 ? I have tried to use the numpy where function which works with 1D arrays like:
import numpy as np
array1 = np.array([2, 2, 2, 0, 2, 0, 2])
print np.where(array1==0, 1, array1)
but I cannot make it working in higher dimensions. I can manually assign the values, but i am looking for a better solution.