当前位置: 首页>>代码示例>>Python>>正文


Python operator.pos方法代码示例

本文整理汇总了Python中operator.pos方法的典型用法代码示例。如果您正苦于以下问题:Python operator.pos方法的具体用法?Python operator.pos怎么用?Python operator.pos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在operator的用法示例。


在下文中一共展示了operator.pos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _add_numeric_methods_unary

# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def _add_numeric_methods_unary(cls):
        """
        Add in numeric unary methods.
        """
        def _make_evaluate_unary(op, opstr):

            def _evaluate_numeric_unary(self):

                self._validate_for_numeric_unaryop(op, opstr)
                attrs = self._get_attributes_dict()
                attrs = self._maybe_update_attributes(attrs)
                return Index(op(self.values), **attrs)

            _evaluate_numeric_unary.__name__ = opstr
            return _evaluate_numeric_unary

        cls.__neg__ = _make_evaluate_unary(operator.neg, '__neg__')
        cls.__pos__ = _make_evaluate_unary(operator.pos, '__pos__')
        cls.__abs__ = _make_evaluate_unary(np.abs, '__abs__')
        cls.__inv__ = _make_evaluate_unary(lambda x: -x, '__inv__') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:base.py

示例2: _add_numeric_methods_unary

# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def _add_numeric_methods_unary(cls):
        """ add in numeric unary methods """

        def _make_evaluate_unary(op, opstr):

            def _evaluate_numeric_unary(self):

                self._validate_for_numeric_unaryop(op, opstr)
                attrs = self._get_attributes_dict()
                attrs = self._maybe_update_attributes(attrs)
                return Index(op(self.values), **attrs)

            return _evaluate_numeric_unary

        cls.__neg__ = _make_evaluate_unary(operator.neg, '__neg__')
        cls.__pos__ = _make_evaluate_unary(operator.pos, '__pos__')
        cls.__abs__ = _make_evaluate_unary(np.abs, '__abs__')
        cls.__inv__ = _make_evaluate_unary(lambda x: -x, '__inv__') 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:base.py

示例3: p_unary_operator

# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def p_unary_operator(p):
    '''unary_operator : '&'
                      | '*'
                      | '+'
                      | '-'
                      | '~'
                      | '!'
    '''
    # reduces to (op, op_str)
    p[0] = ({
        '+': operator.pos,
        '-': operator.neg,
        '~': operator.inv,
        '!': operator.not_,
        '&': 'AddressOfUnaryOperator',
        '*': 'DereferenceUnaryOperator'}[p[1]], p[1]) 
开发者ID:pyglet,项目名称:pyglet,代码行数:18,代码来源:cparser.py

示例4: delete_edge

# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def delete_edge(G, edge, h):
    """
    Given a graph G and one of its edges in tuple form, checks if the deletion
    splits the graph.
    """


    tup = G.es[edge].tuple

    # logging.info("Deleted: %s", tup)

    neighborhood = get_neighborhood_edge(G, tup, h)
    # subtracts local betweennesses in the region, as discussed
    # in the paper
    do_local_betweenness(G, neighborhood, h, operator.neg)
    G.delete_edges(edge)
    fix_betweennesses(G)
    # adds back in local betweennesses after the deletion
    do_local_betweenness(G, neighborhood, h, operator.pos)
    return check_for_split(G, tup) 
开发者ID:GiulioRossetti,项目名称:cdlib,代码行数:22,代码来源:CONGO.py

示例5: split_vertex

# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def split_vertex(G, vToSplit, instr, h):
    """
    Splits the vertex v into two new vertices, each with
    edges depending on s. Returns True if the split
    divided the graph, else False.
    """
    neighborhood = get_neighborhood_vertex(G, vToSplit, h)
    do_local_betweenness(G, neighborhood, h, operator.neg)
    new_index = G.vcount()
    G.add_vertex()
    G.vs[new_index]['CONGA_orig'] = G.vs[vToSplit]['CONGA_orig']
    G.vs[new_index]['pb'] = {uw : 0 for uw in itertools.combinations(G.neighbors(vToSplit), 2)}

    # adding all relevant edges to new vertex, deleting from old one.
    toAdd = list(zip(itertools.repeat(new_index), instr[0]))
    toDelete = list(zip(itertools.repeat(vToSplit), instr[0]))
    G.add_edges(toAdd)
    G.delete_edges(toDelete)
    neighborhood.append(new_index)
    fix_betweennesses(G)
    # logging.info("split: %d, %s", vToSplit, instr)
    do_local_betweenness(G, neighborhood, h, operator.pos)
    # check if the two new vertices are disconnected.
    return check_for_split(G, (vToSplit, new_index)) 
开发者ID:GiulioRossetti,项目名称:cdlib,代码行数:26,代码来源:CONGO.py

示例6: do_local_betweenness

# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def do_local_betweenness(G, neighborhood, h, op=operator.pos):
    """
    Given a neighborhood and depth h, recalculates all betweennesses
    confined to the neighborhood. If op is operator.neg, it subtracts these
    betweennesses from the current ones. Otherwise, it adds them.
    """
    all_pairs_shortest_paths = []
    pathCounts = Counter()
    for i, v in enumerate(neighborhood):
        s_s_shortest_paths = G.get_all_shortest_paths(v, to=neighborhood)#[i+1:])
        all_pairs_shortest_paths += s_s_shortest_paths
    neighSet = set(neighborhood)
    neighSize = len(neighborhood)
    apsp = []
    for path in all_pairs_shortest_paths:
        # path does not go out of region
        if len(neighSet | set(path)) == neighSize:
            pathCounts[(path[0], path[-1])] += 1 # can improve
            apsp.append(path)
    for path in apsp:
        if len(path) <= h + 1:
            update_betweenness(G, path, pathCounts[(path[0], path[-1])], op) 
开发者ID:GiulioRossetti,项目名称:cdlib,代码行数:24,代码来源:CONGO.py

示例7: testNeg

# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def testNeg(self):
        self.unaryCheck(operator.pos) 
开发者ID:myhdl,项目名称:myhdl,代码行数:4,代码来源:test_Signal.py

示例8: test_unary_methods

# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def test_unary_methods(self):
        array = np.array([-1, 0, 1, 2])
        array_like = ArrayLike(array)
        for op in [operator.neg,
                   operator.pos,
                   abs,
                   operator.invert]:
            _assert_equal_type_and_value(op(array_like), ArrayLike(op(array))) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_mixins.py

示例9: test_positive_on_non_number

# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def test_positive_on_non_number(self):
        self.assert_deprecated(operator.pos, args=(np.array('foo'),)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:4,代码来源:test_deprecations.py

示例10: _add_unary_ops

# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def _add_unary_ops(cls):
        cls.__pos__ = cls._create_unary_method(operator.pos)
        cls.__neg__ = cls._create_unary_method(operator.neg)
        cls.__invert__ = cls._create_unary_method(operator.invert) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:sparse.py

示例11: _searchsorted_monotonic

# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def _searchsorted_monotonic(self, label, side='left'):
        if self.is_monotonic_increasing:
            return self.searchsorted(label, side=side)
        elif self.is_monotonic_decreasing:
            # np.searchsorted expects ascending sort order, have to reverse
            # everything for it to work (element ordering, search side and
            # resulting value).
            pos = self[::-1].searchsorted(label, side='right' if side == 'left'
                                          else 'left')
            return len(self) - pos

        raise ValueError('index must be monotonic increasing or decreasing') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:base.py

示例12: positive

# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def positive(x, **_):
    return operator.pos(x) 
开发者ID:mars-project,项目名称:mars,代码行数:4,代码来源:__init__.py

示例13: __pos__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def __pos__(self):
    return NonStandardInteger(operator.pos(self.val)) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:4,代码来源:test_util.py

示例14: test_pos

# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def test_pos(self):
        self.assertRaises(TypeError, operator.pos)
        self.assertRaises(TypeError, operator.pos, None)
        self.assertTrue(operator.pos(5) == 5)
        self.assertTrue(operator.pos(-5) == -5)
        self.assertTrue(operator.pos(0) == 0)
        self.assertTrue(operator.pos(-0) == 0) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_operator.py

示例15: test_starmap

# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def test_starmap():
    yield verify_same, starmap, itertools.starmap, None, pos
    yield verify_same, starmap, itertools.starmap, None, pos, []
    yield (verify_same, starmap, itertools.starmap, None, add,
           [(5, 9), [4, 2]])
    yield (verify_pickle, starmap, itertools.starmap, 2, 0, add,
           [(5, 9), [4, 2]])
    yield (verify_pickle, starmap, itertools.starmap, 2, 1, add,
           [(5, 9), [4, 2]]) 
开发者ID:mila-iqia,项目名称:picklable-itertools,代码行数:11,代码来源:__init__.py


注:本文中的operator.pos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。