Skip to content

Inquiry on the differences between two ways of calculating the dimensional mean #6081

Answered by andersy005
ChenyaoYang123 asked this question in Q&A
Discussion options

You must be logged in to vote

The mean operation is the sum of the values divided by the number of values (by definition). Unfortunately, adding all values up and dividing accumulates floating-point errors. So, presuming your da consists of floating-point numbers, the differences you are seeing between

da.mean(dim="lat",skipna=True).mean(dim="lon",skipna=True)

and

da.mean(dim=["lon","lat"], skipna=True)

are due to differences in accumulated floating-point errors in both operations. To minimize the accumulated floating error, you may want use da.mean(dim=["lon","lat"], ...) instead of the chained .mean("lon", ....).mean("lat", ....) operation.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@max-sixty
Comment options

Answer selected by max-sixty
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants