I have variable:
Q = np.asarray([
[0.20, 0. , 0.3 , 0.1 ],
[0.10, 0. , 0.2 , 0. ],
[0.05, 0. , 0. , 0. ],
[0. , 0. , 0. , 0.05],
], dtype=float)
And I want for each element to find a sum of itself and upper, upper-left, left elements.
If there is no left or upper-left or upper elements we need to make the sum of what we have.
In return I need to get J with these sums.
For example:J[3][3] = Q[3][3]+Q[3][2]+Q[2][2]+Q[2][3]
J[0][1] = Q[0][1]+Q[0][0]
Can I do this via numpy functions only? I want it to be very fast, so NO cycles.
Do you have any ideas?
UPD: The resulting array should be the same size as Q
J = np.array([
[0.2 , 0.2 , 0.3 , 0.4 ],
[0.3 , 0.3 , 0.5 , 0.6 ],
[0.15, 0.15, 0.2 , 0.2 ],
[0.05 , 0.05 , 0. , 0.05 ],
])