In numpy:
Foo = array([[ 3.5, 0. , 2.5, 2. , 0. , 1. , 0. ], [ 0. , 3. , 2.5, 2. , 0. , 0. , 0.5], [ 3.5, 0. , 0. , 0. , 1.5, 0. , 0.5]])
I want to execute a function on Foo so that only non-zero elements change, i.e. for f (x) = x (nonzero) +5:
array([[ 8.5, 0. , 7.5, 7. , 0. , 6. , 0. ], [ 0. , 8. , 8.5, 7. , 0. , 0. , 5.5], [ 8.5, 0. , 0. , 0. , 6.5, 0. , 5.5]])
Also, I want the shape / structure of the array to remain unchanged, so I don't think Foo [np.nonzero (Foo)] will work ...
How to do it in numpy?
thanks!