From 6834e7786fd6fe7dc50dbfd43a1212f539c70a45 Mon Sep 17 00:00:00 2001 From: Robin Date: Fri, 20 Dec 2024 13:31:09 +0100 Subject: [PATCH] i have decided that its probably some weird floaing point thing --- test_read.py | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/test_read.py b/test_read.py index 0ff56eb..f09b6ed 100644 --- a/test_read.py +++ b/test_read.py @@ -22,25 +22,12 @@ print("Mean of U:", U_mean) print("Sum of U:", U_sum) -masked_count = np.ma.count_masked(U) -print("Number of masked values in U:", masked_count) - -nan_count = np.isnan(U).sum() -print("Number of NaN values in U:", nan_count) - -print("Calculating mean manually (takes a bit cause python is slowww)") - -count = 0 -valsum = 0 -for val in U.flat: +sumval = 0 +row = U[0,0,100] +for val in row: if not np.ma.is_masked(val): - # print(val) - valsum += val - count += 1 - -print(f"{valsum=} {valsum/count=} {count=}") - -print(f"The problem is this: why does {valsum/count=} not equal {U_mean=}") + sumval += val +print(f"Why does {np.sum(row)=} not equal {sumval=} ?!") # Close the NetCDF file ncfile.close()