• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python compat.is_iterable函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nengo.utils.compat.is_iterable函数的典型用法代码示例。如果您正苦于以下问题:Python is_iterable函数的具体用法?Python is_iterable怎么用?Python is_iterable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: extend

    def extend(self, keys, unitary=False):
        """Extends the vocabulary with additional keys.

        Creates and adds the semantic pointers listed in keys to the
        vocabulary.

        Parameters
        ----------
        keys : list
            List of semantic pointer names to be added to the vocabulary.
        unitary : bool or list, optional (Default: False)
            If True, all generated pointers will be unitary. If a list of
            strings, any pointer whose name is on the list will be forced to
            be unitary when created.
        """
        if is_iterable(unitary):
            if is_iterable(self.unitary):
                self.unitary.extend(unitary)
            else:
                self.unitary = list(unitary)
        elif unitary:
            if is_iterable(self.unitary):
                self.unitary.extend(keys)
            else:
                self.unitary = list(keys)

        for key in keys:
            if key not in self.keys:
                self[key]
开发者ID:GYGit,项目名称:nengo,代码行数:29,代码来源:vocab.py


示例2: __init__

    def __init__(self, shape_in, filters, biases=None, stride=1, padding=0, activation='linear'):  # noqa: C901
        from nengo.utils.compat import is_iterable, is_integer

        self.shape_in = tuple(shape_in)
        self.filters = filters
        self.stride = stride if is_iterable(stride) else [stride] * 2
        self.padding = padding if is_iterable(padding) else [padding] * 2
        self.activation=activation

        nf = self.filters.shape[0]
        nxi, nxj = self.shape_in[1:]
        si, sj = self.filters.shape[-2:]
        pi, pj = self.padding
        sti, stj = self.stride
        nyi = 1 + max(int(np.ceil((2*pi + nxi - si) / float(sti))), 0)
        nyj = 1 + max(int(np.ceil((2*pj + nxj - sj) / float(stj))), 0)
        self.shape_out = (nf, nyi, nyj)

        self.biases = biases if biases is not None else None
        if self.biases is not None:
            if self.biases.size == 1:
                self.biases.shape = (1, 1, 1)
            elif self.biases.size == np.prod(self.shape_out):
                self.biases.shape = self.shape_out
            elif self.biases.size == self.shape_out[0]:
                self.biases.shape = (self.shape_out[0], 1, 1)
            elif self.biases.size == np.prod(self.shape_out[1:]):
                self.biases.shape = (1,) + self.shape_out[1:]

        super(Conv2d, self).__init__(
            default_size_in=np.prod(self.shape_in),
            default_size_out=np.prod(self.shape_out))
开发者ID:psipeter,项目名称:SYDE552-750,代码行数:32,代码来源:keras_nengo_layers.py


示例3: __init__

    def __init__(self, shape_in, pool_size, strides=None,
                 kind='avg', mode='full'):
        self.shape_in = shape_in
        self.pool_size = (pool_size if is_iterable(pool_size) else
                          [pool_size] * 2)
        self.strides = (strides if is_iterable(strides) else
                        [strides] * 2 if strides is not None else
                        self.pool_size)
        self.kind = kind
        self.mode = mode
        if not all(st <= p for st, p in zip(self.strides, self.pool_size)):
            raise ValueError("Strides %s must be <= pool_size %s" %
                             (self.strides, self.pool_size))

        nc, nxi, nxj = self.shape_in
        nyi_float = float(nxi - self.pool_size[0]) / self.strides[0]
        nyj_float = float(nxj - self.pool_size[1]) / self.strides[1]
        if self.mode == 'full':
            nyi = 1 + int(np.ceil(nyi_float))
            nyj = 1 + int(np.ceil(nyj_float))
        elif self.mode == 'valid':
            nyi = 1 + int(np.floor(nyi_float))
            nyj = 1 + int(np.floor(nyj_float))
        self.shape_out = (nc, nyi, nyj)

        super(Pool2d, self).__init__(
            default_size_in=np.prod(self.shape_in),
            default_size_out=np.prod(self.shape_out))
开发者ID:fmirus,项目名称:nengo_extras,代码行数:28,代码来源:convnet.py


示例4: add_input

    def add_input(self, name, input_vectors, input_scales=1.0):
        # Handle different vocabulary types
        if is_iterable(input_vectors):
            input_vectors = np.matrix(input_vectors)

        # Handle possible different input_scale values for each
        # element in the associative memory
        if not is_iterable(input_scales):
            input_scales = np.matrix([input_scales] * input_vectors.shape[0])
        else:
            input_scales = np.matrix(input_scales)
        if input_scales.shape[1] != input_vectors.shape[0]:
            raise ValueError(
                'Number of input_scale values do not match number of input '
                'vectors. Got: %d, expected %d.' %
                (input_scales.shape[1], input_vectors.shape[0]))

        input = nengo.Node(size_in=input_vectors.shape[1], label=name)

        if hasattr(self, name):
            raise NameError('Name "%s" already exists as a node in the'
                            'associative memory.')
        else:
            setattr(self, name, input)

        nengo.Connection(input, self.elem_input,
                         synapse=None,
                         transform=np.multiply(input_vectors, input_scales.T))
开发者ID:hunse,项目名称:spaun2.0,代码行数:28,代码来源:assoc_mem_2_0.py


示例5: simplify

 def simplify(self):
     is_num = lambda x: isinstance(x, NumExp)
     if isinstance(self.fn, str):
         return self  # cannot simplify
     elif all(map(is_num, self.args)):
         # simplify scalar function
         return NumExp(self.fn(*[a.value for a in self.args]))
     elif all(is_num(a) or is_iterable(a) and all(map(is_num, a))
              for a in self.args):
         # simplify vector function
         return NumExp(self.fn(
             [[aa.value for aa in a] if is_iterable(a) else a.value
              for a in self.args]))
     else:
         return self  # cannot simplify
开发者ID:nengo,项目名称:nengo_ocl,代码行数:15,代码来源:ast_conversion.py


示例6: add_output

    def add_output(self, name, function, synapse=None, **conn_kwargs):
        dims_per_ens = self.dimensions_per_ensemble

        # get output size for each ensemble
        sizes = np.zeros(self.n_ensembles, dtype=int)

        if is_iterable(function) and all(callable(f) for f in function):
            if len(list(function)) != self.n_ensembles:
                raise ValidationError(
                    "Must have one function per ensemble", attr='function')

            for i, func in enumerate(function):
                sizes[i] = np.asarray(func(np.zeros(dims_per_ens))).size
        elif callable(function):
            sizes[:] = np.asarray(function(np.zeros(dims_per_ens))).size
            function = [function] * self.n_ensembles
        elif function is None:
            sizes[:] = dims_per_ens
            function = [None] * self.n_ensembles
        else:
            raise ValidationError("'function' must be a callable, list of "
                                  "callables, or None", attr='function')

        output = nengo.Node(output=None, size_in=sizes.sum(), label=name)
        setattr(self, name, output)

        indices = np.zeros(len(sizes) + 1, dtype=int)
        indices[1:] = np.cumsum(sizes)
        for i, e in enumerate(self.ea_ensembles):
            nengo.Connection(
                e, output[indices[i]:indices[i+1]], function=function[i],
                synapse=synapse, **conn_kwargs)

        return output
开发者ID:JolyZhang,项目名称:nengo,代码行数:34,代码来源:ensemblearray.py


示例7: validate

 def validate(self, instance, rule):
     if is_iterable(rule):
         for r in (itervalues(rule) if isinstance(rule, dict) else rule):
             self.validate_rule(instance, r)
     elif rule is not None:
         self.validate_rule(instance, rule)
     super(LearningRuleTypeParam, self).validate(instance, rule)
开发者ID:GYGit,项目名称:nengo,代码行数:7,代码来源:learning_rules.py


示例8: validate

 def validate(self, instance, rule):
     if is_iterable(rule):
         for lr in rule:
             self.validate_rule(instance, lr)
     elif rule is not None:
         self.validate_rule(instance, rule)
     super(LearningRuleParam, self).validate(instance, rule)
开发者ID:bopo,项目名称:nengo,代码行数:7,代码来源:learning_rules.py


示例9: __getitem__

    def __getitem__(self, item):
        if isinstance(item, slice):
            item = np.arange(len(self))[item]

        if is_iterable(item):
            rval = self.__class__.__new__(self.__class__)
            rval.starts = [self.starts[i] for i in item]
            rval.shape0s = [self.shape0s[i] for i in item]
            rval.shape1s = [self.shape1s[i] for i in item]
            rval.stride0s = [self.stride0s[i] for i in item]
            rval.stride1s = [self.stride1s[i] for i in item]
            rval.buf = self.buf
            rval.names = [self.names[i] for i in item]
            return rval
        else:
            if isinstance(item, np.ndarray):
                item.shape = ()  # avoid numpy DeprecationWarning

            itemsize = self.dtype.itemsize
            shape = (self.shape0s[item], self.shape1s[item])
            byteoffset = itemsize * self.starts[item]
            bytestrides = (itemsize * self.stride0s[item],
                           itemsize * self.stride1s[item])
            return np.ndarray(
                shape=shape, dtype=self.dtype, buffer=self.buf.data,
                offset=byteoffset, strides=bytestrides)
开发者ID:MarcoSaku,项目名称:Spiking-C3D,代码行数:26,代码来源:raggedarray.py


示例10: add_output_mapping

    def add_output_mapping(self, name, output_vectors):
        """Adds another output to the associative memory network.

        Creates a transform with the given output vectors between the
        associative memory element output and a named output node to enable the
        selection of output vectors by the associative memory.

        Parameters
        ----------
        name: str
            Name to use for the output node. This name will be used as
            the name of the attribute for the associative memory network.
        output_vectors: array_like
            The list of vectors to be produced for each match.
        """
        # --- Put arguments in canonical form
        if is_iterable(output_vectors):
            output_vectors = np.array(output_vectors, ndmin=2)

        # --- Check preconditions
        if hasattr(self, name):
            raise ValidationError("Name '%s' already exists as a node in the "
                                  "associative memory." % name, attr='name')

        # --- Make the output node and connect it
        output = nengo.Node(size_in=output_vectors.shape[1], label=name)
        setattr(self, name, output)

        if self.thresh_ens is not None:
            c = nengo.Connection(self.thresh_ens.output, output,
                                 synapse=None, transform=output_vectors.T)
        else:
            c = nengo.Connection(self.elem_output, output,
                                 synapse=None, transform=output_vectors.T)
        self.out_conns.append(c)
开发者ID:GYGit,项目名称:nengo,代码行数:35,代码来源:assoc_mem.py


示例11: __init__

    def __init__(self, fn, in_dims=None, out_dim=None):
        if in_dims is not None and not is_iterable(in_dims):
            in_dims = [in_dims]

        self.fn = fn
        self.in_dims = in_dims
        self.out_dim = out_dim
        self._translator = None
开发者ID:nengo,项目名称:nengo_ocl,代码行数:8,代码来源:ast_conversion.py


示例12: add_input_mapping

    def add_input_mapping(self, name, input_vectors, input_scales=1.0):
        """Adds a set of input vectors to the associative memory network.

        Creates a transform with the given input vectors between the
        a named input node and associative memory element input to enable the
        inputs to be mapped onto ensembles of the Associative Memory.

        Parameters
        ----------
        name: string
            Name to use for the input node. This name will be used as the name
            of the attribute for the associative memory network.

        input_vectors: array_like
            The list of vectors to be compared against.
        input_scales: array_list, optional
            Scaling factor to apply on each of the input vectors. Note that it
            is possible to scale each vector independently.
        """
        # --- Put arguments in canonical form
        n_vectors, d_vectors = input_vectors.shape
        if is_iterable(input_vectors):
            input_vectors = np.array(input_vectors, ndmin=2)
        if not is_iterable(input_scales):
            input_scales = input_scales * np.ones((1, n_vectors))
        else:
            input_scales = np.array(input_scales, ndmin=2)

        # --- Check some preconditions
        if input_scales.shape[1] != n_vectors:
            raise ValidationError("Number of input_scale values (%d) does not "
                                  "match number of input vectors (%d)."
                                  % (input_scales.shape[1], n_vectors),
                                  attr='input_scales')
        if hasattr(self, name):
            raise ValidationError("Name '%s' already exists as a node in the "
                                  "associative memory." % name, attr='name')

        # --- Finally, make the input node and connect it
        in_node = nengo.Node(size_in=d_vectors, label=name)
        setattr(self, name, in_node)
        nengo.Connection(in_node, self.elem_input,
                         synapse=None,
                         transform=input_vectors * input_scales.T)
开发者ID:Stanford-BIS,项目名称:spaun2.0,代码行数:44,代码来源:assoc_mem.py


示例13: function

    def function(self, _function):
        if _function is not None:
            self._check_pre_ensemble('function')
            x = (self.eval_points[0] if is_iterable(self.eval_points) else
                 np.zeros(self._pre.dimensions))
            size = np.asarray(_function(x)).size
        else:
            size = 0

        self._function = (_function, size)
        self._check_shapes()
开发者ID:ZeitgeberH,项目名称:nengo,代码行数:11,代码来源:objects.py


示例14: make_step

    def make_step(self, shape_in, shape_out, dt, rng):
        size_out = shape_out[0] if is_iterable(shape_out) else shape_out

        if self.base_output is None:
            f = self.passthrough
        elif isinstance(self.base_output, Process):
            f = self.base_output.make_step(shape_in, shape_out, dt, rng)
        else:
            f = self.base_output
        return self.Step(size_out, f,
                         to_client=self.to_client,
                         from_client=self.from_client)
开发者ID:jobeng,项目名称:nengo_gui,代码行数:12,代码来源:slider.py


示例15: _broadcast_args

    def _broadcast_args(self, func, args):
        """Apply 'func' element-wise to lists of args"""
        as_list = lambda x: list(x) if is_iterable(x) else [x]
        args = list(map(as_list, args))
        arg_lens = list(map(len, args))
        max_len = max(arg_lens)
        assert all(n in [0, 1, max_len] for n in arg_lens), (
            "Could not broadcast arguments with lengths %s" % arg_lens)

        result = [func(*[a[i] if len(a) > 1 else a[0] for a in args])
                  for i in range(max_len)]
        result = [r.simplify() for r in result]
        return result[0] if len(result) == 1 else result
开发者ID:nengo,项目名称:nengo_ocl,代码行数:13,代码来源:ast_conversion.py


示例16: visit_Return

 def visit_Return(self, expr):
     value = self.visit(expr.value)
     if is_iterable(value):
         self._check_vector_length(len(value))
         if not all(isinstance(v, Expression) for v in value):
             raise ValueError(
                 "Can only return a list of mathematical expressions")
         return ["%s[%d] = %s;" % (OUTPUT_NAME, i, v.to_ocl())
                 for i, v in enumerate(value)] + ["return;"]
     elif isinstance(value, Expression):
         return ["%s[0] = %s;" % (OUTPUT_NAME, value.to_ocl()), "return;"]
     else:
         raise ValueError("Can only return mathematical expressions, "
                          "or lists of expressions")
开发者ID:nengo,项目名称:nengo_ocl,代码行数:14,代码来源:ast_conversion.py


示例17: learning_rule

 def learning_rule(self):
     if self.learning_rule_type is not None and self._learning_rule is None:
         types = self.learning_rule_type
         if isinstance(types, dict):
             self._learning_rule = types.__class__()  # dict of same type
             for k, v in iteritems(types):
                 self._learning_rule[k] = LearningRule(self, v)
         elif is_iterable(types):
             self._learning_rule = [LearningRule(self, v) for v in types]
         elif isinstance(types, LearningRuleType):
             self._learning_rule = LearningRule(self, types)
         else:
             raise ValueError("Invalid type for `learning_rule_type`: %s"
                              % (types.__class__.__name__))
     return self._learning_rule
开发者ID:LittileBee,项目名称:nengo,代码行数:15,代码来源:connection.py


示例18: __getitem__

    def __getitem__(self, key):
        """Return the semantic pointer with the requested name.

        If one does not exist, automatically create one.  The key must be
        a valid semantic pointer name, which is any Python identifier starting
        with a capital letter.
        """
        if not key[0].isupper():
            raise KeyError("Semantic pointers must begin with a capital")
        value = self.pointers.get(key, None)
        if value is None:
            if is_iterable(self.unitary):
                unitary = key in self.unitary
            else:
                unitary = self.unitary
            value = self.create_pointer(unitary=unitary)
            self.add(key, value)
        return value
开发者ID:CamZHU,项目名称:nengo,代码行数:18,代码来源:vocab.py


示例19: learning_rule

    def learning_rule(self):
        """(LearningRule or iterable) Connectable learning rule object(s)."""
        if self.learning_rule_type is not None and self._learning_rule is None:
            types = self.learning_rule_type
            if isinstance(types, dict):
                self._learning_rule = types.__class__()  # dict of same type
                for k, v in iteritems(types):
                    self._learning_rule[k] = LearningRule(self, v)
            elif is_iterable(types):
                self._learning_rule = [LearningRule(self, v) for v in types]
            elif isinstance(types, LearningRuleType):
                self._learning_rule = LearningRule(self, types)
            else:
                raise ValidationError(
                    "Invalid type %r" % types.__class__.__name__,
                    attr='learning_rule_type', obj=self)

        return self._learning_rule
开发者ID:4n6strider,项目名称:nengo,代码行数:18,代码来源:connection.py


示例20: add_output

    def add_output(self, name, output_vectors):
        # Handle different vocabulary types
        if is_iterable(output_vectors):
            output_vectors = np.matrix(output_vectors)

        output = nengo.Node(size_in=output_vectors.shape[1], label=name)

        if hasattr(self, name):
            raise NameError('Name "%s" already exists as a node in the'
                            'associative memory.')
        else:
            setattr(self, name, output)

        if self.threshold_output:
            nengo.Connection(self.thresh_ens.output, output, synapse=None,
                             transform=output_vectors.T)
        else:
            nengo.Connection(self.elem_output, output, synapse=None,
                             transform=output_vectors.T)
开发者ID:hunse,项目名称:spaun2.0,代码行数:19,代码来源:assoc_mem.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python compat.is_number函数代码示例发布时间:2022-05-27
下一篇:
Python spa.Vocabulary类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap