'Integrating 2D data with nans using numpy trapz
I have a 2D matrix U
of data that looks something like this:
0 0.5 0.1 0.3
0 nan 0.4 0.1
nan nan 0.2 nan
The rows index corresponds to height axis data points zz = [0, 2, 10]
and the columns are the horizontal axis data points yy = [0, 3, 7, 9]
(not fixed intervals).
I want to integrate this matrix U
over the zz
and yy
axes. In order to do that I thought about using numpy trapz in the following way:
Uy = np.zeros(len(yy))
for y in range(len(yy)):
U_step = U[:,y][~np.isnan(U[:,y])]
x = zz[0:len(U_step)]
Uy[y] = np.trapz(U_step, x=x)
I = np.trapz(Uy, x=yy)
However, the result I get is not similar to what I expect (value is too low), so I wonder if there is something wrong with the way I integrate, or maybe I should use other functions?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|