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

Python numeric.array函数代码示例

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

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



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

示例1: input_transform

def input_transform( Ashape, Bshape, FFTshape, first ):
    am,an = Ashape
    bm,bn = Bshape
    M,N = FFTshape

    DM = DFT( M )               # get DFT matrix for rows
    DN = DFT( N )               # get DFT matrix for cols

    if( first ):
        c = am*an
        W = unpaddedTransform( DM[:,:am], DN[:an,:] )
    else:
        c = bm*bn
        W = unpaddedTransform( DM[:,:bm], DN[:bn,:] )

    T = []
    for i in range(4*M*N):
        if( first ):
            if( i % 2 == 0 ):
                T.extend( array( [W[i/4,:].real, zeros(c)] ) )
            else:
                T.extend( array( [W[i/4,:].imag, zeros(c)] ) )
        else:
            if( i % 4 == 0 or i % 4 == 3 ):
                T.extend( array( [zeros(c), W[i/4,:].real] ) )
            else:
                T.extend( array( [zeros(c), W[i/4,:].imag] ) )

    return array(T)
开发者ID:Sophrinix,项目名称:nengo,代码行数:29,代码来源:convolution2D.py


示例2: create

    def create(self,net,N=50,dimensions=8,randomize=False):
        vocab={}
        for k in self.nodes.keys():
            node=net.get(k,None)
            if node is None:
                dim=dimensions
                if randomize is False and len(self.nodes[k])+1>dim:
                    dim=len(self.nodes[k])+1
                node=net.make_array(k,N,dim)
            if not hrr.Vocabulary.registered.has_key(id(node)):
                v=hrr.Vocabulary(node.dimension,randomize=randomize)
                v.register(node)
            vocab[k]=hrr.Vocabulary.registered[id(node)]

        # ensure all terms are parsed before starting
        for k,v in self.connect.items():
            pre_name,post_name=k
            for pre_term,post_term in v:
                pre=vocab[pre_name].parse(pre_term).v
                post=vocab[post_name].parse(post_term).v
        
        for k,v in self.connect.items():
            pre_name,post_name=k
            
            t=numeric.zeros((vocab[post_name].dimensions,vocab[pre_name].dimensions),typecode='f')
            for pre_term,post_term in v:
                pre=vocab[pre_name].parse(pre_term).v
                post=vocab[post_name].parse(post_term).v
                t+=numeric.array([pre*bb for bb in post])

            if pre_name==post_name:         
                if pre_name in self.inhibit:
                    for pre_term in vocab[pre_name].keys:
                        pre=vocab[pre_name].parse(pre_term).v*self.inhibit[pre_name]
                        post_value=numeric.zeros(vocab[post_name].dimensions,typecode='f')
                        for post_term in vocab[pre_name].keys:
                            if pre_term!=post_term:
                                post_value+=vocab[post_name].parse(post_term).v
                        t+=numeric.array([pre*bb for bb in post_value])
                if pre_name in self.excite:
                    t+=numeric.eye(len(t))*self.excite[pre_name]
                    
            net.connect(net.get(pre_name),net.get(post_name),transform=t)    
        
        for i,(pre,post) in enumerate(self.ands):
            D=len(pre)
            node=net.make('and%02d'%i,D*N,D)
            for j,p in enumerate(pre):
                t=numeric.zeros((D,vocab[p[0]].dimensions),typecode='f')
                t[j,:]=vocab[p[0]].parse(p[1]).v*math.sqrt(D)
                net.connect(net.get(p[0]),node,transform=t)                
            def result(x,v=vocab[post[0]].parse(post[1]).v):
                for xx in x:
                    if xx<0.4: return [0]*len(v)  #TODO: This is pretty arbitrary....
                return v
            net.connect(node,net.get(post[0]),func=result)    
                
        return net    
开发者ID:Sophrinix,项目名称:nengo,代码行数:58,代码来源:flow.py


示例3: tick

 def tick(self):
     self.counter += 1
     if self.counter % LEARNING_PERIOD == 0: #10 FIXME
         #t_start = time.time()
         delta = -rho * np.array(self.s.get())*0.00001 *.1
         Y = np.array(list(self.Y.get()))
         Y.shape = 300,1
         #Y.shape = 150,1
         da = np.dot(Y, delta)
         da.shape = 300,1 #Bug fix
         ###decoder = np.array(self.origin.decoders)
         ###self.origin.decoders = decoder + da #FIXME: this line takes 50ms to run
         self.origin.decoders += da #FIXME: attempt to make it faster
开发者ID:bjkomer,项目名称:nengo-inverted-pendulum,代码行数:13,代码来源:control_nonlinear_jython.py


示例4: tick

 def tick(self):        
     s = np.array(self.dx.get()) + self.lambd*(np.array(self.x.get()) - np.array(self.x_desired.get()))
     
     # shuld be ddx_r, which in this case is -lambda*dx
     Y = np.array([self.ddx.get()[0], self.dx.get()[0]*abs(self.dx.get()[0]), math.sin(self.x.get()[0])])
     # ddx_r = -lambd * dx
     self.u.set(sum(self.a * Y) - self.kappa * s)
     
     self.s.set(s)
     self.a_val.set(self.a)
 
     dt = 0.001
     self.a -= self.rho*(s*Y)*dt
开发者ID:bjkomer,项目名称:nengo-inverted-pendulum,代码行数:13,代码来源:adaptivependulum.py


示例5: __init__

 def __init__(self,N=None,data=None):
     if data is not None:
         self.v=array(data)
     elif N is not None:
         self.randomize(N)
     else:
         raise Exception('Must specify size or data for HRR')
开发者ID:Elhamahm,项目名称:nengo_1.4,代码行数:7,代码来源:hrr.py


示例6: tick

    def tick(self):

        # Burn through old messages, and only use the latest ones
        # This will allow the controller to keep working if the simulation slows
        # down. In the future they should be synchronized
        while True:
          if self.read_socket( self.sock_in ):
            try:
              data_in = json.loads( self.odom_str )
            except JSONDecodeError:
              break
            self.sensor_data = data_in
          else:
            break
        
        self.position.set([self.sensor_data["roll"]])
        self.velocity.set([self.sensor_data["wx"]])
        
        self.counter += 1
        if self.counter % CONTROL_PERIOD == 0:
          torque = np.array(self.torque.get())[0]
          
          # Send the command to the simulator as a torque
          data_out = '{"force":[0,0,0],"torque":[%f,0,0]}\n' % torque
          self.sock_out.send( data_out )
开发者ID:bjkomer,项目名称:nengo-inverted-pendulum,代码行数:25,代码来源:control_simple_jython.py


示例7: calc_weights

 def calc_weights(self,encoder,decoder):
     self.N1=len(decoder[0])
     self.D=len(decoder)
     self.N2=len(encoder)
     self.getTermination('input').setDimensions(self.N1)
     self.getOrigin('output').setDimensions(self.N2)
     
     self.tables=[]
     self.histograms=[]
     for dim in range(self.D):
         cdfs=[]
         self.tables.append(make_output_table([e[dim] for e in encoder]))
         for i in range(self.N1):
             d=decoder[dim][i]/spike_strength
             if d<0:
                 decoder_sign=-1
                 d=-d
             else:
                 decoder_sign=1
             histogram=compute_histogram(d,[e[dim] for e in encoder])
             cdf=compute_cdf(histogram)
             cdfs.append((decoder_sign,cdf))
         self.histograms.append(cdfs)
     
     return numeric.array(MU.prod(encoder,decoder))
开发者ID:ctn-waterloo,项目名称:nengo_java_gui,代码行数:25,代码来源:dartboard.py


示例8: make

def make(net,name='System',neurons=100,A=[[0]],tau_feedback=0.1):
    A=numeric.array(A)
    assert len(A.shape)==2
    assert A.shape[0]==A.shape[1]
    
    dimensions=A.shape[0]
    state=net.make(name,neurons,dimensions)
    Ap=A*tau_feedback+numeric.identity(dimensions)

    net.connect(state,state,transform=Ap,pstc=tau_feedback)
    if net.network.getMetaData("linear") == None:
        net.network.setMetaData("linear", HashMap())
    linears = net.network.getMetaData("linear")

    linear=HashMap(4)
    linear.put("name", name)
    linear.put("neurons", neurons)
    linear.put("A", MU.clone(A))
    linear.put("tau_feedback", tau_feedback)

    linears.put(name, linear)

    if net.network.getMetaData("templates") == None:
        net.network.setMetaData("templates", ArrayList())
    templates = net.network.getMetaData("templates")
    templates.add(name)

    if net.network.getMetaData("templateProjections") == None:
        net.network.setMetaData("templateProjections", HashMap())
    templateproj = net.network.getMetaData("templateProjections")
    templateproj.put(name, name)
开发者ID:shuw,项目名称:nengo,代码行数:31,代码来源:linear_system.py


示例9: create

    def create(self):
        stored_rule = self.net.make_input("StoredRule", rule_info)

        sensor_in = self.net.make("SENSOR IN", 1, nd, mode = 'direct')
        sensor_data_in = self.net.make("S_DATA IN", 1, nd, mode = 'direct')
        self.add_sink(sensor_in, "sensor_in") ##>]##
        self.add_sink(sensor_data_in, "sensor_data_in") ##>]##

        ant_add = self.net.make("ANT ADD", 1, nd, mode = 'direct')
        ant_add.addDecodedTermination("SENSOR", np.array(vocab.hrr["ANTxSENSOR"].get_transform_matrix()) * 0.4, 0.001, False)
        ant_add.addDecodedTermination("S_DATA", np.array(vocab.hrr["ANTxS_DATA"].get_transform_matrix()) * 0.6, 0.001, False)
        self.net.connect("SENSOR IN", ant_add.getTermination("SENSOR"))
        self.net.connect("S_DATA IN", ant_add.getTermination("S_DATA"))

        cconv_pos_out = self.net.make("CConv Pos Out", 1, nd, mode = 'direct')
        cconv_pos_ens = make_convolution(self.net, "CCONV -> POS", None, None, cconv_pos_out, nn_cconv, radius = 6, \
                                         invert_second = True, quick = True)
        self.net.connect("StoredRule", cconv_pos_ens.getTermination("A"))
        self.net.connect("ANT ADD", cconv_pos_ens.getTermination("B"))

        cleanup_pos = CleanupMem("CleanupPos", pos_list, en_mut_inhib = True, tau_in = pstc_base, in_scale = 1.0, threshold = 0.4)
        self.net.add(cleanup_pos)
        self.net.connect(cconv_pos_out.getOrigin("X"), cleanup_pos.getTermination("Input"))

        cconv_rule_out = self.net.make("CConv Rule Out", 1, nd, mode = 'direct')
        cconv_rule_ens = make_convolution(self.net, "CCONV -> RULE", None, None, cconv_rule_out, nn_cconv, radius = 6, \
                                          invert_second = True, quick = True)
        self.net.connect("StoredRule", cconv_rule_ens.getTermination("A"))
        self.net.connect(cleanup_pos.getOrigin("X"), cconv_rule_ens.getTermination("B"))

        action = self.net.make("ACTION", 1, nd, mode = 'direct')
        action.addDecodedTermination("Input", vocab.hrr["~(CONSxACTION)"].get_transform_matrix(), 0.001, False)
        action_cu = CleanupMem("CleanupAction", action_list, en_mut_inhib = True, tau_in = pstc_base, \
                                     threshold = 0.15, in_scale = 1.2, tau_smooth = pstc_base)
        self.net.add(action_cu)
        self.net.connect(cconv_rule_out, action.getTermination("Input"))
        self.net.connect(action, action_cu.getTermination("Input"))
        self.add_source(action_cu.getOrigin("X"), "act_out") ##]>##

        action_data = self.net.make("ACTION DATA", 1, nd, mode = 'direct')
        action_data.addDecodedTermination("Input", vocab.hrr["~(CONSxA_DATA)"].get_transform_matrix(), 0.001, False)
        action_data_cu = CleanupMem("CleanupActionData", action_data_list, en_mut_inhib = True, tau_in = pstc_base, \
                                     threshold = 0.15, in_scale = 1.2, tau_smooth = pstc_base)
        self.net.add(action_data_cu)
        self.net.connect(cconv_rule_out, action_data.getTermination("Input"))
        self.net.connect(action_data, action_data_cu.getTermination("Input"))
        self.add_source(action_data_cu.getOrigin("X"), "act_data_out") ##]>##        
开发者ID:tcstewar,项目名称:parser,代码行数:47,代码来源:fulltest_cogsci.py


示例10: alen

def alen(a):
    """Return the length of a Python object interpreted as an array
    of at least 1 dimension.
    """
    try:
        return len(a)
    except TypeError:
        return len(array(a,ndmin=1))
开发者ID:radical-software,项目名称:radicalspam,代码行数:8,代码来源:fromnumeric.py


示例11: _init

    def _init(self, dtype):
        self.dtype = numeric.dtype(dtype)
        if dtype is ntypes.double:
            itype = ntypes.int64
            fmt = "%24.16e"
            precname = "double"
        elif dtype is ntypes.single:
            itype = ntypes.int32
            fmt = "%15.7e"
            precname = "single"
        elif dtype is ntypes.longdouble:
            itype = ntypes.longlong
            fmt = "%s"
            precname = "long double"
        elif dtype is ntypes.half:
            itype = ntypes.int16
            fmt = "%12.5e"
            precname = "half"
        else:
            raise ValueError(repr(dtype))

        machar = MachAr(
            lambda v: array([v], dtype),
            lambda v: _frz(v.astype(itype))[0],
            lambda v: array(_frz(v)[0], dtype),
            lambda v: fmt % array(_frz(v)[0], dtype),
            "numpy %s precision floating point number" % precname,
        )

        for word in ["precision", "iexp", "maxexp", "minexp", "negep", "machep"]:
            setattr(self, word, getattr(machar, word))
        for word in ["tiny", "resolution", "epsneg"]:
            setattr(self, word, getattr(machar, word).flat[0])
        self.max = machar.huge.flat[0]
        self.min = -self.max
        self.eps = machar.eps.flat[0]
        self.nexp = machar.iexp
        self.nmant = machar.it
        self.machar = machar
        self._str_tiny = machar._str_xmin.strip()
        self._str_max = machar._str_xmax.strip()
        self._str_epsneg = machar._str_epsneg.strip()
        self._str_eps = machar._str_eps.strip()
        self._str_resolution = machar._str_resolution.strip()
        return self
开发者ID:Xatpy,项目名称:echomesh,代码行数:45,代码来源:getlimits.py


示例12: connect

    def connect(self, and_neurons=50):

        # ensure all terms are parsed before starting
        for k,v in self.connections.items():
            pre_name,post_name=k
            for pre_term,post_term in v:
                pre=self.spa.sources[pre_name].parse(pre_term).v
                post=self.spa.sinks[post_name].parse(post_term).v
        
        for k,v in self.connections.items():
            pre_name,post_name=k
            
            t=numeric.zeros((self.spa.sinks[post_name].dimensions,self.spa.sources[pre_name].dimensions),typecode='f')
            for pre_term,post_term in v:
                pre=self.spa.sources[pre_name].parse(pre_term).v
                post=self.spa.sinks[post_name].parse(post_term).v
                t+=numeric.array([pre*bb for bb in post])

            if pre_name==post_name:         
                if pre_name in self.inhibit:
                    for pre_term in self.spa.sources[pre_name].keys:
                        pre=self.spa.sources[pre_name].parse(pre_term).v*self.inhibit[pre_name]
                        post_value=numeric.zeros(self.spa.sources[post_name].dimensions,typecode='f')
                        for post_term in self.spa.sources[pre_name].keys:
                            if pre_term!=post_term:
                                post_value+=self.spa.sources[post_name].parse(post_term).v
                        t+=numeric.array([pre*bb for bb in post_value])
                if pre_name in self.excite:
                    t+=numeric.eye(len(t))*self.excite[pre_name]
                    
            self.spa.net.connect('source_'+pre_name,'sink_'+post_name,transform=t)    
        
        for i,(pre,post) in enumerate(self.ands):
            D=len(pre)
            aname='and%02d'%i
            self.net.make(aname,D*and_neurons,D)
            for j,p in enumerate(pre):
                t=numeric.zeros((D,self.spa.sources[p[0]].dimensions),typecode='f')
                t[j,:]=self.spa.sources[p[0]].parse(p[1]).v*math.sqrt(D)
                self.spa.net.connect('source_'+p[0],self.name+'.'+aname,transform=t)                
            def result(x,v=self.spa.sinks[post[0]].parse(post[1]).v):
                for xx in x:
                    if xx<0.4: return [0]*len(v)  #TODO: This is pretty arbitrary....
                return v
            self.spa.net.connect(self.name+'.'+aname,'sink_'+post[0],func=result)    
开发者ID:Elhamahm,项目名称:nengo_1.4,代码行数:45,代码来源:flow.py


示例13: _init

    def _init(self, dtype):
        self.dtype = numeric.dtype(dtype)
        if dtype is ntypes.double:
            itype = ntypes.int64
            fmt = '%24.16e'
            precname = 'double'
        elif dtype is ntypes.single:
            itype = ntypes.int32
            fmt = '%15.7e'
            precname = 'single'
        elif dtype is ntypes.longdouble:
            itype = ntypes.longlong
            fmt = '%s'
            precname = 'long double'
        elif dtype is ntypes.half:
            itype = ntypes.int16
            fmt = '%12.5e'
            precname = 'half'
        else:
            raise ValueError, repr(dtype)

        machar = MachAr(lambda v:array([v], dtype),
                        lambda v:_frz(v.astype(itype))[0],
                        lambda v:array(_frz(v)[0], dtype),
                        lambda v: fmt % array(_frz(v)[0], dtype),
                        'numpy %s precision floating point number' % precname)

        for word in ['precision', 'iexp',
                     'maxexp','minexp','negep',
                     'machep']:
            setattr(self,word,getattr(machar, word))
        for word in ['tiny','resolution','epsneg']:
            setattr(self,word,getattr(machar, word).flat[0])
        self.max = machar.huge.flat[0]
        self.min = -self.max
        self.eps = machar.eps.flat[0]
        self.nexp = machar.iexp
        self.nmant = machar.it
        self.machar = machar
        self._str_tiny = machar._str_xmin.strip()
        self._str_max = machar._str_xmax.strip()
        self._str_epsneg = machar._str_epsneg.strip()
        self._str_eps = machar._str_eps.strip()
        self._str_resolution = machar._str_resolution.strip()
        return self
开发者ID:1950,项目名称:sawbuck,代码行数:45,代码来源:getlimits.py


示例14: output_transform

def output_transform(dimensions):
    ifft=np.array(discrete_fourier_transform_inverse(dimensions))

    def makeifftrow(D,i):
        if i==0 or i*2==D: return ifft[i]
        if i<=D/2: return ifft[i]+ifft[-i].real-ifft[-i].imag*1j
        return np.zeros(dimensions)
    ifftm=np.array([makeifftrow(dimensions,i) for i in range(dimensions/2+1)])
    
    ifftm2=[]
    for i in range(dimensions/2+1):
        ifftm2.append(ifftm[i].real)
        ifftm2.append(-ifftm[i].real)
        ifftm2.append(-ifftm[i].imag)
        ifftm2.append(-ifftm[i].imag)
    ifftm2=np.array(ifftm2)

    return ifftm2.T
开发者ID:shiva16,项目名称:nengo_extract,代码行数:18,代码来源:convolution.py


示例15: calc_output_gates

 def calc_output_gates(self,buffer,vocab):
     r=[]
     for p in self.productions:
         v=p.rhs.get(buffer,None)
         if v!=True:
             r.append([0])
         else:
             r.append([-1])
     return numeric.array(r).T        
开发者ID:Elhamahm,项目名称:nengo_1.4,代码行数:9,代码来源:nps.py


示例16: calc_input_transform

 def calc_input_transform(self,buffer,vocab):
     r=[]
     for p in self.productions:
         v=p.lhs.get(buffer,None)
         if v is None:
             r.append([0]*vocab.dimensions)
         else:
             r.append(vocab.parse(v).v*p.lhs_scale)
     return numeric.array(r)        
开发者ID:Elhamahm,项目名称:nengo_1.4,代码行数:9,代码来源:nps.py


示例17: rhs_route

 def rhs_route(self,source,sink,conv,weight):
     t=[]
     vocab=self.spa.sinks[sink]
     for n in self.names:
         rule=self.rules[n]
         if rule.rhs_route.get((source,sink,conv),None)==weight:
             t.append([-1])
         else:
             t.append([0])
     return numeric.array(t).T
开发者ID:ctn-waterloo,项目名称:nengo_java_gui,代码行数:10,代码来源:bgrules.py


示例18: make

def make(net,name='System',neurons=100,A=[[0]],tau_feedback=0.1):
    A=numeric.array(A)
    assert len(A.shape)==2
    assert A.shape[0]==A.shape[1]
    
    dimensions=A.shape[0]
    state=net.make(name,neurons,dimensions)
    Ap=A*tau_feedback+numeric.identity(dimensions)

    net.connect(state,state,transform=Ap,pstc=tau_feedback)
开发者ID:hunse,项目名称:nengo_1.4,代码行数:10,代码来源:linear_system.py


示例19: rhs_direct

 def rhs_direct(self,sink_name):
     t=[]
     vocab=self.spa.sinks[sink_name]
     for n in self.names:
         rule=self.rules[n]
         row=rule.rhs_direct.get(sink_name,None)
         if row is None: row=[0]*vocab.dimensions
         else: row=vocab.parse(row).v
         t.append(row)
     return numeric.array(t).T
开发者ID:ctn-waterloo,项目名称:nengo_java_gui,代码行数:10,代码来源:bgrules.py


示例20: input_transform

def input_transform(dimensions,first,invert=False):
    fft=np.array(discrete_fourier_transform(dimensions))

    M=[]
    for i in range((dimensions/2+1)*4):
        if invert: row=fft[-(i/4)]
        else: row=fft[i/4]
        if first:
            if i%2==0:
                row2=np.array([row.real,np.zeros(dimensions)])
            else:
                row2=np.array([row.imag,np.zeros(dimensions)])
        else:
            if i%4==0 or i%4==3:
                row2=np.array([np.zeros(dimensions),row.real])
            else:    
                row2=np.array([np.zeros(dimensions),row.imag])
        M.extend(row2)
    return M
开发者ID:shiva16,项目名称:nengo_extract,代码行数:19,代码来源:convolution.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python numeric.broadcast函数代码示例发布时间:2022-05-27
下一篇:
Python multicomplex.bicomplex函数代码示例发布时间: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