I have a list that I want to build a kernel from [90,50,10]
What I want to do is to get a kernel that looks like -
[[90,0,0]
[50,0,0]
[10,0,0]
[0,90,0]
[0,50,0]
[0,10,0]
[0,0,90]
[0,0,50]
[0,0,10]]
I can implement this using a loop, AND I tried doing something in the lines of this -
k = np.array([90,50,10])
for i in k:
d = np.zeros((3,3))
np.fill_diagonal(d, i)
print(d)
[[90. 0. 0.]
[ 0. 90. 0.]
[ 0. 0. 90.]]
[[50. 0. 0.]
[ 0. 50. 0.]
[ 0. 0. 50.]]
[[10. 0. 0.]
[ 0. 10. 0.]
[ 0. 0. 10.]]
The issue is that to reorder the rows, I will need another iteration and np.fill_diagonal is an in-place method so I cant use list comprehensions.
I am looking for a way I can solve this in a vectorized manner without any loops, using only numpy and in a single line of code.
EDIT:
The preferred solution should be able to build a 25X5 kernel if I use a 5X1 array like [90,50,40,30,10]