[Numpy-discussion] ignore NAN in numpy.true_divide()
questions anon
questions.anon at gmail.com
Mon Dec 5 21:53:51 EST 2011
Thanks for responding. I have tried several ways of adding the command, one
of which is:
for i in TSFC:
if N.any(N.isnan(TSFC)):
break
else:
pass
but nothing is happening, is there some particular way I need to add this
command? I have posted all below:
netCDF_list=[]
for dir in glob.glob(MainFolder + '*/01/')+ glob.glob(MainFolder +
'*/02/')+ glob.glob(MainFolder + '*/12/'):
#print dir
for ncfile in glob.glob(dir + '*.nc'):
netCDF_list.append(ncfile)
slice_counter=0
print netCDF_list
for filename in netCDF_list:
ncfile=netCDF4.Dataset(filename)
TSFC=ncfile.variables['T_SFC'][:]
fillvalue=ncfile.variables['T_SFC']._FillValue
TSFC=MA.masked_values(TSFC, fillvalue)
for a in TSFC:
if N.any(N.isnan(TSFC)):
break
else:
pass
for i in xrange(0,len(TSFC)-1,1):
slice_counter +=1
#print slice_counter
try:
running_sum=N.add(running_sum, TSFC[i])
except NameError:
print "Initiating the running total of my
variable..."
running_sum=N.array(TSFC[i])
TSFC_avg=N.true_divide(running_sum, slice_counter)
N.set_printoptions(threshold='nan')
print "the TSFC_avg is:", TSFC_avg
On Tue, Dec 6, 2011 at 9:45 AM, David Cournapeau <cournape at gmail.com> wrote:
> On Mon, Dec 5, 2011 at 5:29 PM, questions anon <questions.anon at gmail.com>
> wrote:
> > Maybe I am asking the wrong question or could go about this another way.
> > I have thousands of numpy arrays to flick through, could I just identify
> > which arrays have NAN's and for now ignore the entire array. is there a
> > simple way to do this?
>
> Doing np.any(np.isnan(a)) for an array a should answer this exact question
>
> David
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20111206/0c0e3188/attachment.html>
More information about the NumPy-Discussion
mailing list