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


Python MA类代码示例

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


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

示例1: testConcatenate

 def testConcatenate (self):
     "test concatenate"
     assert eq (MA.concatenate((self.a[:3], self.a[3:])), [0,1,2,3,4,5])
     m = self.m
     assert eq (MA.concatenate((m, m)), [[1,2,3], [11,12,13], [1,2,3], [11,12,13]])
     assert eq (MA.concatenate((m, m), axis = 1), 
                [[1,2,3,1,2,3],[11,12,13,11,12,13]])
开发者ID:mikeswamp,项目名称:numeric_copy,代码行数:7,代码来源:ntest.py

示例2: testMultipleDimensionCreation

 def testMultipleDimensionCreation (self):       
     'Test creation of multidimensional arrays.'
     alist = [[2,3],[4,5]]
     x = MA.array(alist)
     assert x.shape == (2,2)
     y = MA.array([x, x + 1, x + 2])
     assert y.shape == (3,2,2)
开发者ID:mikeswamp,项目名称:numeric_copy,代码行数:7,代码来源:ntest.py

示例3: testDiagonal

 def testDiagonal (self):
     "Test the diagonal function."
     b=MA.array([[1,2,3,4],[5,6,7,8]]*2)
     assert eq(MA.diagonal(b), [1,6,3,8])
     assert eq(MA.diagonal(b, -1), [5,2,7])
     c = MA.array([b,b])
     assert eq(MA.diagonal(c,1), [[2,7,4], [2,7,4]])
开发者ID:mikeswamp,项目名称:numeric_copy,代码行数:7,代码来源:ntest.py

示例4: from_summset

 def from_summset(cls, ds, shaped_like=None):
     self = cls(ds.name)
     st = time.time()
     cols = ds.get_columns()
     if shaped_like is not None:
         for axis in xtab_axes(shaped_like):
             try:
                 col = ds[axis.name]
             except KeyError:
                 pass
             else:
                 self.axes.append(CrossTabAxis.from_col(col, axis.values))
                 cols.remove(col)
     for col in cols:
         if col.is_discrete() and not col.name.startswith('_'):
             self.axes.append(CrossTabAxis.from_col(col))
     if not self.axes:
         raise Error('dataset %r must have at least one discrete column' % 
                     (ds.name,))
     indices = [axis.indices.filled() for axis in self.axes]
     masks = [axis.indices.mask() for axis in self.axes]
     map = MA.transpose(MA.array(indices, mask=masks))
     shape = self.get_shape()
     for col in ds.get_columns():
         if col.is_scalar():
             self.add_table(col.name, 
                            data=self.from_vector(map, col.data, shape),
                            label=col.label)
     elapsed = time.time() - st
     soom.info('%r crosstab generation took %.3f, %.1f rows/s' % 
                 (self.name, elapsed, len(map) / elapsed))
     return self
开发者ID:timchurches,项目名称:NetEpi-Analysis,代码行数:32,代码来源:CrossTab.py

示例5: accumulate24Hourly

def accumulate24Hourly(data):
    """Returns 12-hourly data accumulated to 24-hours."""
    newTimeValues=[]
    taxis=data.getTime()
    tunits=data.units
    print len(data.getTime())
    newarray=[]

    for i in range((tlen/2)):
        p1=data(time=slice(i,i+1))
        p2=data(time=slice(i+1,i+2))
        accum=p1+p2
        newarray.append(accum)
        newTimeValues.append(p2.getTime()[0])

    array=MA.concatenate(newarray)
    array=MA.array(array, 'f', fill_value=data.getMissing())
    axes=data.getAxisList()
    newTimeAxis=cdms.createAxis(newTimeValues)
    newTimeAxis.units=tunits
    newTimeAxis.designateTime()
    newTimeAxis.id=newTimeAxis.long_name=newTimeAxis.title="time"
    
    newaxes=[newTimeAxis]+axes[1:]
    var=cdms.createVariable(array, axes=newaxes, id=data.id)
    for att in ("units", "long_name"):
        setattr(var, att, getattr(data, att))
    return var 
开发者ID:arsen3d,项目名称:wepoco-web,代码行数:28,代码来源:makePlots.py

示例6: Init_diag

def Init_diag(Ain,Aout,fignum):
	global Ptot,RatioM,Tmincrit,Cpa,Cpv,Lv,namincrit,Hmincrit,Tmaxcrit,Tminopt
	global Ratiofig,fig_hauteur,fig_longueur,RatioAxes,lineprops,lineprops_HR,x1,y1,x3,y3
	Ptot=101325.0
	MO=15.9994
	MN=14.0067
	MAr=39.948
	Mair=0.78084*2*MN+0.20946*2*MO+0.009340*MAr
	MH=1.00794
	MH2O=2*MH+MO
	RatioM=MH2O/Mair
	Tmincrit=-30.0
	Cpa=Cpas(C2K(Tmincrit))
	Cpv=Cpvap(C2K(0.1))
	Lv=ChLv(C2K(0.1))
	namincrit=RatioM*Pvap(Tmincrit)/(Ptot-Pvap(Tmincrit))
	Hmincrit=Cpa*Tmincrit+namincrit*(Lv+Cpv*Tmincrit)
	Tmaxcrit=260.0
	Tminopt=-30.0
	Ratiofig=21.0/29.7
	fig_hauteur=6 #inches
	fig_longueur=fig_hauteur/Ratiofig
	figure(fignum,figsize=(fig_longueur,fig_hauteur))
	lineprops = dict(linewidth=0.5, color='gray', linestyle='-',antialiased=True)
	lineprops_HR = dict(linewidth=1, color='blue', linestyle='-',antialiased=True)
	Tinit=20.0
	Cpa=Cpas(C2K(Tinit))
	Cpv=Cpvap(C2K(Tinit))
	Lv=ChLv(C2K(Tinit))
	maskin=Ma.getmask(Ain.car)
	maskout=Ma.getmask(Aout.car)
	
# Il s'agit ici de fixer les valeurs moyennes de Cpa,Cpv et Lv
# en faisant le calcul de l'air moyen (i.e. au centre du diagramme
# le calcul s'arrête à 1e-6 de différence sur Cpa,Cpv et Lv
	crit=True
	while crit:
		Ain.car=Ma.array(Ain.car,copy=0,mask=maskin) 
		Aout.car=Ma.array(Aout.car,copy=0,mask=maskout) 
		Fill_Air(Ain)
		Fill_Air(Aout)
		Amoy=air()
		Amoy.definir(["H","na"],[mean([Ain.car[0],Aout.car[0]]),
						            mean([Ain.car[1],Aout.car[1]])])
		Fill_Air(Amoy)
		Tmoy=Amoy.car[2]
		Cpa_new=Cpas(C2K(Tmoy))
		Cpv_new=Cpvap(C2K(Tmoy))
		Lv_new=ChLv(C2K(Tmoy))
		crit=((Cpa-Cpa_new)**2+(Cpv-Cpv_new)**2+(Lv-Lv_new)**2)>1e-6
		Cpa=Cpa_new
		Cpv=Cpv_new
		Lv=Lv_new

	LH,Lna,LT,LHR,Lair=Return_levels_HnaTHR(Ain,Aout)
	x1,y1=Transf_xy(Lna[0],Lair[0].car[0])
	x3,y3=Transf_xy(Lna[-1],Lair[2].car[0])
	RatioAxes=(y3-y1)/(x3-x1)
	return LH,Lna,LT,LHR,Lair
开发者ID:Ticonderoga,项目名称:Routines,代码行数:59,代码来源:DiagHumid-old.py

示例7: testReshape

 def testReshape (self):
     "test reshape"
     w = MA.reshape(self.m, (-1,2))
     assert eq(w, [[1,2],[3,11],[12,13]])
     w = MA.reshape (self.a, (2,3))
     assert eq(w, [[0, 1, 2], [3, 4, 5]])
     self.failUnlessRaises(ValueError, MA.reshape, MA.arange(5), (3,2))
     self.failUnlessRaises(ValueError, MA.reshape, self.a, (4,-1))
     self.failUnlessRaises(ValueError, MA.reshape, self.a, (5,6))
开发者ID:mikeswamp,项目名称:numeric_copy,代码行数:9,代码来源:ntest.py

示例8: _check

 def _check(a):
     self.assertEqual(a['na'], na)
     self.assertEqual(a['maa'], maa)
     self.assertEqual(a['na'][500:-500], na[500:-500])
     self.assertEqual(a['maa'][500:-500], maa[500:-500])
     scatter = Numeric.array(xrange(0, len(na), 3))
     self.assertEqual(a['na'].take(scatter), Numeric.take(na, scatter))
     self.assertEqual(Numeric.take(a['na'],scatter), 
                      Numeric.take(na, scatter))
     self.assertEqual(MA.take(a['maa'], scatter), MA.take(maa, scatter))
开发者ID:timchurches,项目名称:NetEpi-Analysis,代码行数:10,代码来源:soomarraytest.py

示例9: testLogical

 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,代码行数:10,代码来源:ntest.py

示例10: testZeros

 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,代码行数:10,代码来源:ntest.py

示例11: testArange

 def testArange(self):
     "Test arange"
     x = MA.arange(5)
     assert eq(x, [0,1,2,3,4])
     x = MA.arange(4, 6)
     assert eq(x, [4,5])
     x = MA.arange(0, 1.5, .5)
     assert eq (x, [0.0, 0.5, 1.0])
     assert len(MA.arange(5,3,2)) == 0
     x = MA.arange(3L)
     assert x[1] == 1L
     assert x.typecode() == MA.PyObject
开发者ID:mikeswamp,项目名称:numeric_copy,代码行数:12,代码来源:ntest.py

示例12: testOnes

 def testOnes(self):
     "Test ones"
     y = MA.ones((2,3))
     assert y.shape == (2,3)
     assert y.typecode() == MA.Int
     assert eq(y.flat, 1)
     z = MA.ones((2,3), MA.Float)
     assert z.shape == (2,3)
     assert eq(y, z)
     w = MA.ones((2,3), MA.Int16)
     assert eq(w, MA.array([[1,1,1],[1,1,1]],'s'))
     self.failUnlessRaises(ValueError, MA.ones, (-5,))
开发者ID:mikeswamp,项目名称:numeric_copy,代码行数:12,代码来源:ntest.py

示例13: testTypecodeSpecifying

 def testTypecodeSpecifying(self):
     'Test construction using the type codes.'
     from Precision import typecodes
     thetypes = typecodes['Integer']  \
                + typecodes['UnsignedInteger'] \
                + typecodes['Float'] \
                + typecodes['Complex'] 
     for t in thetypes:
         x = MA.array([1,2,3], t)
         assert x.typecode() == t
     x = MA.array(['hi', 'hoo'], 'c')
     assert x.typecode() == 'c'
开发者ID:mikeswamp,项目名称:numeric_copy,代码行数:12,代码来源:ntest.py

示例14: testIndexing

    def testIndexing (self):
        'Test indexing operations.'
        x = MA.array([0,1,2,3,4,5])
        for i in range(len(x)):
            assert i == x[i]
        x[2] = 20
        assert eq(x, x[...])
        w = MA.array([None])
        assert w.typecode() == MA.PyObject
        assert w[0] is None
        assert isinstance(x[2], types.IntType)
        assert x[2] == 20
        x = MA.array([0,1,2,3,4,5,6])
        assert eq (x[4:1:-1], [4,3,2])
        assert eq(x[4:1:-2], [4,2])
        assert eq(x[::-1], [6, 5,4,3,2,1,0])
        assert eq(x[2:-1], [2,3,4,5])
        m = MA.array([[1,2,3],[11,12,13]])
        assert m[0,2] == 3
        assert isinstance(m[0,2], types.IntType)
        assert eq(m[...,1], [2,12])
        assert eq(MA.arange(6)[..., MA.NewAxis], [[0],[1],[2],[3],[4],[5]])
        x = MA.array([1,2,3])
        y = MA.array(x)
        x[0] == 66
        assert y[0] != 66
        b=MA.array([[1,2,3,4],[5,6,7,8]]*2)
#        assert b[1:1].shape == (0,4)
#        assert b[1:1, :].shape == (0,4)
#        assert b[10:].shape == (0,4)
        assert eq(b[2:10], [[1,2,3,4],[5,6,7,8]])
        assert eq(b[2:10, ...], [[1,2,3,4],[5,6,7,8]])
开发者ID:mikeswamp,项目名称:numeric_copy,代码行数:32,代码来源:ntest.py

示例15: derive_format_str

 def derive_format_str(self, data):
     if len(data) == 0:
         return self.default_format_str
     width = 10
     max = MA.maximum(MA.absolute(data))
     if max > 0:
         decimals = width - math.log(max, 10) - 2
         if decimals < 0:
             decimals = 0
     elif max >= 0.00001:
         decimals = 8
     else:
         return '%10.10g'
     return '%%%d.%df' % (width, decimals)
开发者ID:timchurches,项目名称:NetEpi-Analysis,代码行数:14,代码来源:DataTypes.py


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