本文整理汇总了Python中numeric.array函数的典型用法代码示例。如果您正苦于以下问题:Python array函数的具体用法?Python array怎么用?Python array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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
示例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
示例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
示例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')
示例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 )
示例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))
示例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)
示例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") ##]>##
示例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))
示例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
示例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)
示例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
示例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
示例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