Nov-08-2019, 06:23 PM
Folks,
I came across a problem involving arrays that I am having trouble finding solution, could it help me? Or give me some tips?
Basically, I have an array below that repeats the same pattern of diagonals with increasing rows and columns. You need to create a program that gets the user the number of rows and columns and automatically creates an array with this pattern.
-4 1 0 0 0 1 0 0
1 -4 1 0 0 0 1 0
0 1 -4 1 0 0 0 1
0 0 1 -4 1 0 0 0
0 0 0 1 -4 0 0 0
1 0 0 0 0 -4 1 0
0 1 0 0 0 1 -4 1
0 0 1 0 0 0 1 -4
I enter values on the main diagonal with an np.fill_diagonal function, but I can't include the values in the other diagonals.
Thanks !!
I came across a problem involving arrays that I am having trouble finding solution, could it help me? Or give me some tips?
Basically, I have an array below that repeats the same pattern of diagonals with increasing rows and columns. You need to create a program that gets the user the number of rows and columns and automatically creates an array with this pattern.
-4 1 0 0 0 1 0 0
1 -4 1 0 0 0 1 0
0 1 -4 1 0 0 0 1
0 0 1 -4 1 0 0 0
0 0 0 1 -4 0 0 0
1 0 0 0 0 -4 1 0
0 1 0 0 0 1 -4 1
0 0 1 0 0 0 1 -4
I enter values on the main diagonal with an np.fill_diagonal function, but I can't include the values in the other diagonals.
Thanks !!