本文整理汇总了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)