I have a list of numbers as follows:
list = [5,6,4,7,8]
I need to build a 2d NumPy array using the list above applying the following logic:
arr = np.array([[k1+k2, -k2, 0, 0, 0],
[-k2, k2+k3, -k3, 0, 0],
[0, -k3, k3+k4, -k4, 0],
[0, 0, -k4, k4+k5, -k5],
[0, 0, 0, -k5, k5]])
k - are the elements in the list, for ex: k1=5, k2=6 and so on.
So, the expected output in this example should look like:
arr = np.array([[11, -6, 0, 0, 0],
[-6, 10, -4, 0, 0],
[0, -4, 11, -7, 0],
[0, 0, -7, 15, -8],
[0, 0, 0, -8, 8]])
Appreciate any help to build this logic.