本文整理汇总了Python中MA.put方法的典型用法代码示例。如果您正苦于以下问题:Python MA.put方法的具体用法?Python MA.put怎么用?Python MA.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MA
的用法示例。
在下文中一共展示了MA.put方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_col
# 需要导入模块: import MA [as 别名]
# 或者: from MA import put [as 别名]
def from_col(cls, col, values=None):
self = cls(col.name, col.label, col=col)
if values is not None:
# this_values = sets.Set(col.inverted.keys())
# wanted_values = sets.Set(values)
# if not wanted_values.issubset(this_values):
# missing_vals = [repr(v) for v in (wanted_values - this_values)]
# raise Error('column %r values mismatch - %r' %
# (self.name, ', '.join(missing_vals)))
self.values = values
else:
self.values = col.inverted.keys()
self.values.sort()
self.indices = fully_masked(len(col))
if 0:
# AM - the .inverted attribute of filtered datasets is returning
# invalid row indices, and the summ code relies on these indices,
# so the following code cannot be used until they are fixed.
self.axis_map = {}
for i, v in enumerate(self.values):
self.axis_map[v] = i
vec = col.inverted.get(v)
if vec is not None:
for idx in vec:
try:
self.indices[idx] = i
except IndexError:
print col.name, idx
raise
MA.put(self.indices, vec, i)
else:
axis_map = dict([(v, i) for i, v in enumerate(self.values)])
for i, v in enumerate(col.data):
try:
self.indices[i] = axis_map[v]
except KeyError:
pass
self.axis_map = axis_map
return self
示例2: testPut
# 需要导入模块: import MA [as 别名]
# 或者: from MA import put [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