当前位置: 首页>>代码示例>>Python>>正文


Python MA.zeros方法代码示例

本文整理汇总了Python中MA.zeros方法的典型用法代码示例。如果您正苦于以下问题:Python MA.zeros方法的具体用法?Python MA.zeros怎么用?Python MA.zeros使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MA的用法示例。


在下文中一共展示了MA.zeros方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testPut

# 需要导入模块: import MA [as 别名]
# 或者: from MA import zeros [as 别名]
 def testPut (self):
     "test put and putmask"
     x=MA.arange(5)
     MA.put (x, [1,4],[10,40])
     assert eq(x, [0,10,2,3,40])
     
     x=MA.arange(5) * 1.0
     MA.put (x, [1,4],[10.,40.])
     assert eq(x, [0.,10.,2.,3.,40.])
     
     x=MA.arange(5) 
     MA.put (x, [1,4],[10])
     assert eq(x, [0,10,2,3,10])
     
     x=MA.arange(5) 
     MA.put (x, [1,4],10)
     assert eq(x, [0,10,2,3,10])
     
     x=MA.arange(5) 
     MA.put (x, [0,1,2,3], [10,20])
     assert eq(x, [10,20,10,20,4])
     
     x=MA.arange(5) 
     MA.put (x, [[0,1],[2,3]], [10,20])
     assert eq(x, [10,20,10,20,4])
     
     x = MA.arange(5).astype(MA.Float32)
     MA.put (x, [1,4],[10.,40.])
     assert eq(x, [0,10,2,3,40])
     
     x=MA.arange(6)*1.0
     x.shape=(2,3)
     MA.put(x, [1,4],[10,40])
     assert eq(x, [[0,10,2],[3,40,5]])
     
     x=MA.arange(5)
     MA.putmask (x, [1,0,1,0,1], [-1,10,20,30,40]) 
     assert eq(x, [-1,1,20,3,40])
     
     x=MA.arange(10)
     MA.putmask(x, MA.ones(10), 5)
     assert eq(x, 5*MA.ones(10))
     
     x=MA.arange(10)*1.0
     x=x.astype(MA.Float32)
     MA.putmask(x, [0,0,1,0,0,0,0,0,0,1], 3.0)
     assert eq(x, [0.,1.,3.,3.,4.,5.,6.,7.,8.,3.])
     
     x=MA.zeros((10,),MA.PyObject)
     MA.putmask(x, [0,0,1,0,0,0,1,0,0,1], 0.0)
     assert x[2] == 0.
     assert x[1] == 0
     
     x=MA.zeros((5,2),MA.PyObject)
     m=MA.zeros((5,2), MA.Int)
     m[3,1] = 1
     m[2,0] = 1
     MA.putmask(x, m, 0.0)
     assert x[3,1] == 0.0
     assert x[2,0] == 0
开发者ID:mikeswamp,项目名称:numeric_copy,代码行数:62,代码来源:ntest.py

示例2: testZeros

# 需要导入模块: import MA [as 别名]
# 或者: from MA import zeros [as 别名]
 def testZeros(self):
     "Test zeros"
     y = MA.zeros((2,3))
     assert y.shape == (2,3)
     assert y.typecode() == MA.Int
     assert eq(y, 0)
     z = MA.zeros((2,3), MA.Float)
     assert z.shape == (2,3)
     assert eq (y, z)
     self.failUnlessRaises(ValueError, MA.zeros, (-5,))
开发者ID:mikeswamp,项目名称:numeric_copy,代码行数:12,代码来源:ntest.py

示例3: testLogical

# 需要导入模块: import MA [as 别名]
# 或者: from MA import zeros [as 别名]
 def testLogical (self):
     "Test logical_and, logical_or, sometrue, alltrue"
     x = MA.array([1,1,0,0])
     y = MA.array([1,0,1,0])
     assert eq(MA.logical_and (x,y), [1,0,0,0])
     assert eq(MA.logical_or (x,y), [1,1,1,0])
     assert MA.sometrue(x)
     assert not MA.sometrue(MA.zeros((3,)))
     assert MA.alltrue(MA.ones((3,)))
     assert not MA.alltrue(x)
开发者ID:mikeswamp,项目名称:numeric_copy,代码行数:12,代码来源:ntest.py

示例4: testOperators

# 需要导入模块: import MA [as 别名]
# 或者: from MA import zeros [as 别名]
    def testOperators (self):
        "Test the operators +, -, *, /, %, ^, &, |"
        x = MA.array([1.,2.,3.,4.,5.,6.])
        y = MA.array([-1.,2.,0.,2.,-1, 3.])
        assert eq(x + y, [0., 4., 3., 6., 4., 9.])
        assert eq(x - y, [2., 0., 3., 2., 6., 3.])
        assert eq(x * y, [-1., 4., 0., 8., -5., 18.])
        assert eq(y / x, [-1, 1., 0., .5, -.2, .5])
        assert eq(x**2, [1., 4., 9., 16., 25., 36.])
        xc = MA.array([1.,2.,3.,4.,5.,6.])
        xc += y
        assert eq(xc, x + y)
        xc = MA.array([1.,2.,3.,4.,5.,6.])
        xc -= y
        assert eq(xc, x - y)
        yc = MA.array(y, copy=1)
        yc /= x
        assert eq ( yc, y / x)
        xc = MA.array([1.,2.,3.,4.,5.,6.])
        y1 = [-1.,2.,0.,2.,-1, 3.]
        xc *= y1
        assert eq(xc, x * y1)

        assert eq (x + y, MA.add(x, y))
        assert eq (x - y, MA.subtract(x, y))
        assert eq (x * y, MA.multiply(x, y))
        assert eq (y / x, MA.divide (y, x))
        d = x / y
        assert d[2] is MA.masked 
        assert (MA.array(1) / MA.array(0)) is MA.masked
        assert eq (x**2, MA.power(x,2))
        x = MA.array([1,2])
        y = MA.zeros((2,))
        assert eq (x%x, y)
        assert eq (MA.remainder(x,x), y)
        assert eq (x <<1, [2,4])
        assert eq (MA.left_shift(x,1), [2,4])
        assert eq (x >>1, [0,1])
        assert eq (MA.right_shift(x,1), [0,1])
        assert eq (x & 2, [0,2])
        assert eq (MA.bitwise_and (x, 2), [0,2])
        assert eq (x | 1, [1,3])
        assert eq (MA.bitwise_or (x, 1), [1,3])
        assert eq (x ^ 2, [3,0])
        assert eq (MA.bitwise_xor(x,2), [3,0])
#        x = divmod(MA.array([2,1]), MA.array([1,2]))
#        assert eq (x[0], [2,0])
#        assert eq (x[1], [0,1])
        assert (4L*MA.arange(3)).typecode() == MA.PyObject
开发者ID:mikeswamp,项目名称:numeric_copy,代码行数:51,代码来源:ntest.py

示例5: testDotOuter

# 需要导入模块: import MA [as 别名]
# 或者: from MA import zeros [as 别名]
 def testDotOuter (self):
     "test the dot product and outer product"
     assert MA.dot(self.a, self.a) == 55
     assert eq (MA.add.outer(self.a[:3], self.a[:3]),
                [[0,1,2],[1,2,3],[2,3,4]])
     assert eq (MA.outerproduct(self.a[:3], self.a[:3]),
                [[0,0,0],[0,1,2],[0,2,4]])
     a = MA.arange(4)
     b = MA.arange(3)
     c = MA.zeros((4,3))
     c[0] = a[0]*b
     c[1] = a[1]*b
     c[2] = a[2]*b
     c[3] = a[3]*b
     assert eq(c, MA.outerproduct(a,b))
开发者ID:mikeswamp,项目名称:numeric_copy,代码行数:17,代码来源:ntest.py

示例6: x

# 需要导入模块: import MA [as 别名]
# 或者: from MA import zeros [as 别名]
# And plot these babies:
x.plot([Y1,Y2,Y3,zero],xs=[X,X,X,[0.,2.*MA.pi]]) # You MUST pass a list of slab, even if only one slab
# or you can plot then 1 by 1
# first let's clear
x('kill G0.S0')
x('kill G0.S1')
x('kill G1.S0')
x('kill G1.S1')

# Now the tan is pretty ugly because of extreme let's mask everything
# that is greater than 1.5 and redraw that
Y3=MA.masked_greater(Y3,1.5)

# Also we're going to add error bars 10% of the value
# dx for the sin
YY1=MA.zeros((2,npoints),typecode=MA.Float)
YY1[0]=Y1
YY1[1]=Y1*.1
x.Graph[0].Set[0].type='xydx'
x.Graph[0].Set[0].errorbar.status='on'
x.Graph[0].Set[0].errorbar.color='red'
# dy for the cos
YY2=MA.zeros((2,npoints),typecode=MA.Float)
YY2[0]=Y2
YY2[1]=Y2*.1
x.Graph[0].Set[1].type='xydy'
x.Graph[0].Set[1].errorbar.status='on'
x.Graph[0].Set[1].errorbar.color=x.Graph[0].Set[1].line.color
# dy and dx for the tan
YY3=MA.zeros((3,npoints),typecode=MA.Float)
YY3[0]=Y3
开发者ID:UV-CDAT,项目名称:cdat-site,代码行数:33,代码来源:xmgrace_tutorial_Numeric.py

示例7: writeOutput

# 需要导入模块: import MA [as 别名]
# 或者: from MA import zeros [as 别名]
def writeOutput(infile, var, lat, lon, dav, dmax, dmin, sdupper, sdlower, location):
    """
    Writes an output file of the variables generated.
    """

    location=location.replace(" ","_").lower()
    f=cdms.open(infile)
    
    mapit={"apcp":("rainfall","l/m^2"), "tmpk":("temperature","K")} 
    varname=mapit[var][0]
    units=mapit[var][1]
    datetime=os.path.split(infile)[-1].split(".")[1]
    outfile="%s_%s_%s.nc" % (datetime, location, varname)
    outpath=os.path.split(infile)[0]
    outfile=os.path.join(outpath, outfile)
    fout=cdms.open(outfile, "w")
    latax=cdms.createAxis([lat])
    latax.units="degrees_north"
    latax.id=latax.standard_name=latax.long_name="latitude"
    lonax=cdms.createAxis([lon])
    lonax.units="degrees_east"
    lonax.id=lonax.standard_name=lonax.long_name="longitude"   
    tax=f[var].getTime() #f(var, level=slice(0,1), lat=slice(0,1), lon=slice(0,1)).getTime()
    timeax=cdms.createAxis(Numeric.array(tax[0:tlen],'d'))
    timeax.designateTime()
    timeax.units=tax.units
    #timeax.id=timeax.standard_name=timeax.long_name="time"
    timeax.id="time"
    timeax.title=tax.title
    timeax.delta_t=tax.delta_t
    timeax.init_time=tax.init_time
    timeax.actual_range=tax.actual_range
    del timeax.axis
    del timeax.calendar
    metadata=f[var]
    fv=metadata.missing_value
    newshape=(len(timeax), len(latax), len(lonax))
    
    maxFound=20. # Set as our max value if not greater
    
    for v in ((dav, "average"), (dmax, "maximum"), (dmin, "minimum"), \
      (sdupper, "plus_std_dev"), (sdlower, "minus_std_dev"), ("always10", "always10")):
        if type(v[0])==type("jlj") and v[0]=="always10": 
            print "Creating always equal to 10 variable."
            always10=MA.zeros(newshape, 'f')+10.
            #print always10.shape, dav.shape, type(dav)
            newvar=cdms.createVariable(always10,  axes=[timeax, latax, lonax], id=v[1], fill_value=fv)
            newvar.longname="always10"
        else:
            data=v[0]
            name=varname+"_"+v[1]
            if not type(data)==type([1,2]):
                data=data(squeeze=1)
            data=MA.resize(data, newshape)
            newvar=cdms.createVariable(data, axes=[timeax, latax, lonax], id=name, fill_value=fv)
            newvar.long_name="%s - %s" % (varname.title(), v[1].replace("_", " "))
            newvar.units=metadata.units

        (dummy,vmax)=vcs.minmax(newvar)
        if vmax>maxFound:
            maxFound=vmax
        fout.write(newvar)
        fout.sync()
        del newvar

    fout.close()
    return (outfile, varname, datetime, maxFound)
开发者ID:arsen3d,项目名称:wepoco-web,代码行数:69,代码来源:makePlots.py

示例8: xrange

# 需要导入模块: import MA [as 别名]
# 或者: from MA import zeros [as 别名]
  fill_value = fice._FillVlaue
fice_masked = MA.transpose(MA.masked_values(ficea,fill_value),(1,2,0))

hlat = ice1.variables["hlat"]  # hlat[49]
hlon = ice1.variables["hlon"]  # hlon[100]


dimf     = fice.shape  # Define an array to hold long-term monthly means.
ntime    = fice.shape[0]
nhlat    = fice.shape[1]
nhlon    = fice.shape[2]

nmo    = 0
month  = nmo+1

icemon = MA.zeros((nhlat,nhlon),MA.Float0)
for i in xrange(fice_masked.shape[0]):
  for j in xrange(fice_masked.shape[1]):
    icemon[i,j] = MA.average(fice_masked[i,j,0:ntime:12])

#
#  Fill the places where icemon is zero with the fill value.
#
icemon = MA.masked_values(icemon,0.,rtol=0.,atol=1.e-15)
icemon = MA.filled(icemon,value=fill_value)

                       # Calculate the January (nmo=0) average.


nsub = 16 # Subscript location of northernmost hlat to be plotted.
开发者ID:akrherz,项目名称:me,代码行数:32,代码来源:ngl09p.py

示例9: len

# 需要导入模块: import MA [as 别名]
# 或者: from MA import zeros [as 别名]
 a=cdms.open(file_xml)
 data=a[var]
 print '----  ', i, model[i],data.shape
 start_time = data.getTime().asComponentTime()[0]
 end_time = data.getTime().asComponentTime()[-1]
 print 'start time: ',start_time,'  end time:',end_time
 time_len = len(data.getTime())
 print 'time axis lenght: ', time_len
 a.close()
 dm=str(i)+' = '+model[i]
 model_description=model_description+', '+dm

#
print;print '__________________';print
# set up an output array for the global time series
glan=MA.zeros([len(model),time_len],MA.Float)
#
# Loop over the files and read data into memory.  Subtract the average
# annual cycle and area-average the departure maps for a global departure/anomaly
# time series.
#
#start_time = cdtime.comptime(1979,2,1)
#end_time   = cdtime.comptime(1984,12,1)
#
for i in range(0,len(model)):
 file_xml = os.path.join(sys.prefix,'sample_data/'+var+'_'+model[i]+'.xml')
 #a=cdms.open('/pcmdi/AMIP3/amip/mo/'+var+'/'+model[i]+'/'+var+'_'+model[i]+'.xml')
 a=cdms.open(file_xml)
 data=a(var,time=(start_time,end_time),squeeze=1)
 a.close()
 ac=cdutil.ANNUALCYCLE.climatology(data(time=(start_time, end_time, 'cob')))
开发者ID:UV-CDAT,项目名称:cdat-site,代码行数:33,代码来源:global_anomalies_new.py


注:本文中的MA.zeros方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。