From: Bruce F. <br...@cl...> - 2011-08-29 16:10:41
|
Closing the loop...I found the difficulty and applied this: var = np.nan_to_num(np.divide(var1,var2)) See this page: http://psaffrey.wordpress.com/2010/07/30/numpy-and-nan-again/ --------------------------------------- Bruce W. Ford Clear Science, Inc. br...@cl... On Sun, Aug 28, 2011 at 4:03 PM, Bruce Ford <br...@cl...> wrote: > Getting a strange result trying to divide two 3d arrays. I am getting > a matrix of NaNs regardless of how I divide and I can't determine why. > > #opened a NetCDF file using python-netcdf4 > > var1 = nc_file.variables['var1'] ###shape = [31,181,360] with a > values ranging from 0 - 243 and NO NaNs in the array, dtype float32 > var2 = nc_file.variables['var2'] ###shape = [31,181,360] with a > values ranging from 0 - 4 (mostly zeros) and NO NaNs in the array, > dtype float32 > > np.seterr(all='ignore') #in case problem has something do to with > dividing by zero > > var1/var2 ###gives array of NaNs with shape of 31,181,360 > > #doing the division one slice at a time doesn't help... > for x in range(1,var1.shape[0]): > var[x,:,:] = var1[x,:,:]/var2[x,:,:] ###gives array of > NaNs with shape of 31,181,360 > > var = np.divide(var1,var2) ###gives array of NaNs with shape of 31,181,360 > > > print "<p>where max: " + np.where(var1 == np.max(var1)) #prints > (array([28]), array([79]), array([182])) > print var1[28,79,182] #print 545 > print var2[28,79,182] ##prints 6 > > #so there are values in this location that should not result in an > NaN. Instead I get an entire array of NaNs > > What am I missing? > > Bruce > > --------------------------------------- > Bruce W. Ford > Clear Science, Inc. > br...@cl... > |