本文整理汇总了Python中MA.array方法的典型用法代码示例。如果您正苦于以下问题:Python MA.array方法的具体用法?Python MA.array怎么用?Python MA.array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MA
的用法示例。
在下文中一共展示了MA.array方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testMultipleDimensionCreation
# 需要导入模块: import MA [as 别名]
# 或者: from MA import array [as 别名]
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)
示例2: testDiagonal
# 需要导入模块: import MA [as 别名]
# 或者: from MA import array [as 别名]
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]])
示例3: Init_diag
# 需要导入模块: import MA [as 别名]
# 或者: from MA import array [as 别名]
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
示例4: testLogical
# 需要导入模块: import MA [as 别名]
# 或者: from MA import array [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)
示例5: testTypecodeSpecifying
# 需要导入模块: import MA [as 别名]
# 或者: from MA import array [as 别名]
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'
示例6: testSpacesaver
# 需要导入模块: import MA [as 别名]
# 或者: from MA import array [as 别名]
def testSpacesaver (self):
"Test the spacesaver property (Travis Oliphant)"
# Test of savespace property: Travis Oliphant
a = MA.array([1,2,3,4],savespace=1)
assert a.spacesaver()
self.assertEqual(a.typecode(), 's')
b = MA.array(a,'f')
self.assertEqual(b.typecode(), 'f')
assert b.spacesaver()
a.savespace(0)
assert not a.spacesaver()
assert b.spacesaver()
d = 4 * b
assert b.typecode() == d.typecode()
self.failUnlessRaises, TypeError, MA.arccos, (b/10.0)
示例7: from_summset
# 需要导入模块: import MA [as 别名]
# 或者: from MA import array [as 别名]
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
示例8: accumulate24Hourly
# 需要导入模块: import MA [as 别名]
# 或者: from MA import array [as 别名]
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
示例9: testIndexing
# 需要导入模块: import MA [as 别名]
# 或者: from MA import array [as 别名]
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]])
示例10: testSort
# 需要导入模块: import MA [as 别名]
# 或者: from MA import array [as 别名]
def testSort (self):
"Test sort, argsort, argmax, argmin"
s = (3,2,5,1,4,0)
sm = [s, MA.array(s)[::-1]]
se = MA.array(s)[0:0]
assert eq(MA.sort(s), self.a)
assert len(MA.sort(se)) == 0
assert eq(MA.argsort(s), [5,3,1,0,4,2])
assert len(MA.argsort(se)) == 0
assert eq(MA.sort(sm, axis = -1), [[0,1,2,3,4,5],[0,1,2,3,4,5]])
assert eq(MA.sort(sm, axis = 0), [[0,2,1,1,2,0],[3,4,5,5,4,3]])
assert MA.argmax(s) == 2
assert MA.argmin(s) == 5
assert eq(MA.argmax(sm, axis=-1), [2,3])
assert eq(MA.argmax(sm, axis=1), [2,3])
assert eq(MA.argmax(sm, axis=0), [0,1,0,1,0,1])
assert eq(MA.argmin(sm, axis=-1), [5,0])
assert eq(MA.argmin(sm, axis=1), [5,0])
示例11: testOperators
# 需要导入模块: import MA [as 别名]
# 或者: from MA import array [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
示例12: testOnes
# 需要导入模块: import MA [as 别名]
# 或者: from MA import array [as 别名]
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,))
示例13: __getitem__
# 需要导入模块: import MA [as 别名]
# 或者: from MA import array [as 别名]
def __getitem__(self, key):
index = self.dict[key]
blob = self.store[index]
if blob.type == BLOB_ARRAY:
return MmapArray(blob)
elif blob.type == BLOB_FILLED:
data = MmapArray(blob)
blob = self.store[blob.other]
mask = MmapArray(blob)
return MA.array(data, mask = mask)
elif blob.type == BLOB_STRING:
return blob.as_str()
else:
raise Error('bad BLOB type %s in index' % blob.type)
示例14: copyTest
# 需要导入模块: import MA [as 别名]
# 或者: from MA import array [as 别名]
def copyTest (self):
"Test how MA works with the copy module."
import copy
x = MA.array([1,2,3])
y = [1, x, 3]
c1 = copy.copy(x)
assert MA.allclose(x,c1)
x[1] = 4
assert not MA.allclose(x,c1)
c2 = copy.copy(y)
assert id(c2[1]) == id(x)
c3 = copy.deepcopy(y)
assert id(c3[1]) != id(x)
assert MA.allclose(c3[1], x)
示例15: testReductions
# 需要导入模块: import MA [as 别名]
# 或者: from MA import array [as 别名]
def testReductions (self):
"Tests of reduce attribute."
a = MA.arange(6)
m = MA.array([[1,2,3],[11,12,13]])
assert MA.add.reduce(a) == 15
assert MA.multiply.reduce(m.shape) == len(m.flat)
assert eq(MA.add.reduce (m, 0), [12,14,16])
assert eq(MA.add.reduce (m, -1), [6,36])
assert eq(MA.multiply.reduce (m, 0), [11,24,39])
assert eq(MA.multiply.reduce (m, -1), [6,11*12*13])
assert MA.add.reduce([1]) == 1
assert MA.add.reduce([]) == 0
assert MA.multiply.reduce([]) == 1
assert MA.minimum.reduce(a) == 0
assert MA.maximum.reduce(a) == 5