0

I was writing the following code to add two values from two different netcdf files.

import netCDF4 as nc
m1 = nc.Dataset('m1.nc')
m2 = nc.Dataset('m2.nc')
a = m1.variables(['pr'][364][100][100] + m2.variables(['pr'][364][100][100]
print a

This code gave me an parsing error - invalid syntax. I thought that since we can extract the values in these cells, I should be able to add them and assign them to a variable. Clearly, I am wrong, can someone explain why and how this mechanism works?

1

This does work but you have syntax errors, just remove the parentheses.

a = m1.variables['pr'][364][100][100] + m2.variables['pr'][364][100][100]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.