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. [email protected] On Sun, Aug 28, 2011 at 4:03 PM, Bruce Ford <[email protected]> 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. > [email protected] > ------------------------------------------------------------------------------ EMC VNX: the world's simplest storage, starting under $10K The only unified storage solution that offers unified management Up to 160% more powerful than alternatives and 25% more efficient. Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev _______________________________________________ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
