reproduced difference between means in python and c++ entirely in python still dont know why
This commit is contained in:
parent
e1d11e84ce
commit
314082c160
|
|
@ -1,3 +1,3 @@
|
|||
build
|
||||
build/
|
||||
.vscode
|
||||
data
|
||||
data/
|
||||
|
|
@ -3,14 +3,16 @@
|
|||
#include <cuda_runtime.h>
|
||||
#include <device_launch_parameters.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
int main() {
|
||||
std::string path = "data/MERRA2_400.inst6_3d_ana_Np.20120101.nc4";
|
||||
std::string variable = "T";
|
||||
auto x = readData(path, variable);
|
||||
|
||||
// Print some values from the file to see that it worked
|
||||
// Calculate the mean of the data to see if it works.
|
||||
float sum = 0;
|
||||
int n = 0;
|
||||
int skipped = 0;
|
||||
|
|
|
|||
16
test_read.py
16
test_read.py
|
|
@ -10,7 +10,7 @@ print(ncfile.variables.keys())
|
|||
|
||||
U = ncfile.variables['T'][:]
|
||||
|
||||
# Check the shape of the variable (it should be 3D)
|
||||
# Check the shape of the variable
|
||||
print("Shape of U:", U.shape)
|
||||
|
||||
# Compute the mean of the variable across all axes (for all elements in U)
|
||||
|
|
@ -28,5 +28,19 @@ 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:
|
||||
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=}")
|
||||
|
||||
# Close the NetCDF file
|
||||
ncfile.close()
|
||||
|
|
|
|||
Loading…
Reference in New Issue