本文整理匯總了Python中MA.ones方法的典型用法代碼示例。如果您正苦於以下問題:Python MA.ones方法的具體用法?Python MA.ones怎麽用?Python MA.ones使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MA
的用法示例。
在下文中一共展示了MA.ones方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testPut
# 需要導入模塊: import MA [as 別名]
# 或者: from MA import ones [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
示例2: testOnes
# 需要導入模塊: import MA [as 別名]
# 或者: from MA import ones [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,))
示例3: testLogical
# 需要導入模塊: import MA [as 別名]
# 或者: from MA import ones [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)