Python Forum

Full Version: diagonal matix
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all, I want to create a 400x400 diagonal matrix with upper and lower cases. I can do it manually but it would take hours. The matix should look like this one:

[[ 4.1 -2.5 0. 0. 0. 0. 0. 0. 0. 0. ]
[-0.3 2.8 -2.5 0. 0. 0. 0. 0. 0. 0. ]
[ 0. -1.5 4. -2.5 0. 0. 0. 0. 0. 0. ]
[ 0. 0. -2.7 5.2 -2.5 0. 0. 0. 0. 0. ]
[ 0. 0. 0. -3.9 6.4 -2.5 0. 0. 0. 0. ]
[ 0. 0. 0. 0. -5.1 7.6 -2.5 0. 0. 0. ]
[ 0. 0. 0. 0. 0. -6.3 8.8 -2.5 0. 0. ]
[ 0. 0. 0. 0. 0. 0. -7.5 10. -2.5 0. ]
[ 0. 0. 0. 0. 0. 0. 0. -8.7 11.2 -2.5]
[ 0. 0. 0. 0. 0. 0. 0. 0. -9.9 12.4]]
Thank you in advance
I'm not sure what you mean by "cases" here. Where do the values come from, as in what governs what the diagonal and off-diagonal elements of this matrix are? Can you use NumPy's facilities for array creation to help? Why do you need to create such a large matrix by hand anyway?