Python Forum

Full Version: Help whit array
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 !!
looks like a homework assignment. What have you tried so far?