I have two arrays, Result and X. I would like to add non-zero row elements of Result to each element of X. The desired output is attached.
import numpy as np
Result=np.array([[ 0. , -2.46421304, -4.99073939, -5.79902063, 0. ],
[-10. , 0. , -4.99073939, 0. , 0. ],
[-10. , -2.46421304, 0. , -5.79902063, 0. ],
[-10. , 0. , -4.99073939, 0. , 0. ],
[ 0. , -2.46421304, -4.99073939, -5.79902063, 0. ]])
X=np.array([10,2.46421304,4.99073939,5.79902063,0])
Desired output:
array([[ 0. , 10-2.46421304, 10-4.99073939, 10-5.79902063, 0. ],
[2.46421304-10. , 0. , 2.46421304-4.99073939, 0. , 0. ],
[4.99073939-10. , 4.99073939-2.46421304, 0. , 4.99073939-5.79902063, 0. ],
[5.79902063-10. , 0. , 5.79902063-4.99073939, 0. , 0. ],
[ 0. , 0-2.46421304, 0-4.99073939, 0-5.79902063, 0. ]])