當前位置: 首頁>>代碼示例>>Python>>正文


Python MA.put方法代碼示例

本文整理匯總了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
開發者ID:timchurches,項目名稱:NetEpi-Analysis,代碼行數:41,代碼來源:CrossTab.py

示例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
開發者ID:mikeswamp,項目名稱:numeric_copy,代碼行數:62,代碼來源:ntest.py


注:本文中的MA.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。