So, lets say I have an identity matrix AB and I would like to change the diagonal ones into 5 and the immediate off diagonal into 8s
AB=np.identity(5)
AB
array([[1., 0., 0., 0., 0.],
[0., 1., 0., 0., 0.],
[0., 0., 1., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 0., 0., 0., 1.]])
row=AB.shape[0]
col=AB.shape[1]
new = AB
for i in range (0,row):
for j in range (0,col):
if AB[i,j] !=0:
new[i,j] = 5
## if j+1 == 0:
## new[i,j+1] = 8
print(new)
[[5. 0. 0. 0. 0.]
[0. 5. 0. 0. 0.]
[0. 0. 5. 0. 0.]
[0. 0. 0. 5. 0.]
[0. 0. 0. 0. 5.]]
With the code above I am able to change the 1's into 5's but I haven't been able to figure out how to change the first off diagonal to 8s on both sides of the main diagonal