Вы можете добавить следующий оператор печати, и цикл будет объясняться на каждой итерации:
n=4
matrix=np.zeros((n,n))
for i in range (0,n):
for j in range(0,i+1):
print(f'inserting {i-j+1} into the matrix at row index {i}, columns index {j}')
matrix[i,j]=i-j+1
Когда вы запустите его, вы получите такой вывод:
inserting 1 into the matrix at row index 0, columns index 0
inserting 2 into the matrix at row index 1, columns index 0
inserting 1 into the matrix at row index 1, columns index 1
...
inserting 3 into the matrix at row index 3, columns index 1
inserting 2 into the matrix at row index 3, columns index 2
inserting 1 into the matrix at row index 3, columns index 3
ИВаша матрица заполнена как и раньше:
>>> matrix
array([[1., 0., 0., 0.],
[2., 1., 0., 0.],
[3., 2., 1., 0.],
[4., 3., 2., 1.]])
Только для справки:
>>> matrix
array([[1., 0., 0., 0.], #<- "row" index 0
[2., 1., 0., 0.], #<- "row" index 1
[3., 2., 1., 0.], #<- "row" index 2
[4., 3., 2., 1.]]) #<- "row" index 3
# ^ ... ^
# "col" 0 "col" 3