All Samples(268296) | Call(268286) | Derive(0) | Import(10)
range([start,] stop[, step]) -> list of integers Return a list containing an arithmetic progression of integers. range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0. When step is given, it specifies the increment (or decrement). For example, range(4) returns [0, 1, 2, 3]. The end point is omitted! These are exactly the valid indices for a list of 4 elements.
src/n/i/NiPypeold-HEAD/examples/spm_tutorial.py NiPypeold(Download)
def subjectinfo(subject_id):
print "Subject ID: %s\n"%str(subject_id)
output = []
names = ['Task-Odd','Task-Even']
for r in range(4):
onsets = [range(15,240,60),range(45,240,60)]
output.insert(r,
"""
# collect all the con images for each contrast.
contrast_ids = range(1,len(contrasts)+1)
l2source = pe.Node(nio.DataGrabber(infields=['fwhm', 'con']), name="l2source")
l2source.inputs.template=os.path.abspath('spm_tutorial/l1output/*/con*/*/_fwhm_%d/con_%04d.img')
# iterate over all contrast images
src/n/i/NiPypeold-HEAD/examples/fsl_tutorial2.py NiPypeold(Download)
def sort_copes(files):
numelements = len(files[0])
outfiles = []
for i in range(numelements):
outfiles.insert(i,[])
for j, elements in enumerate(files):
outfiles[i].append(elements[i])
def subjectinfo(subject_id):
print "Subject ID: %s\n"%str(subject_id)
output = []
names = ['Task-Odd','Task-Even']
for r in range(4):
onsets = [range(15,240,60),range(45,240,60)]
output.insert(r,
src/n/i/NiPypeold-HEAD/examples/freesurfer_tutorial.py NiPypeold(Download)
def subjectinfo(subject_id):
print "Subject ID: %s\n"%str(subject_id)
output = []
names = ['Task-Odd','Task-Even']
for r in range(4):
onsets = [range(15,240,60),range(45,240,60)]
output.insert(r,
l2inputnode = pe.Node(interface=util.IdentityInterface(fields=['contrasts',
'hemi']),
name='inputnode')
l2inputnode.iterables = [('contrasts', range(1,len(contrasts)+1)),
('hemi', ['lh','rh'])]
"""
src/c/s/csc-pysparse-1.1.1.4/examples/poisson_test.py csc-pysparse(Download)
def poisson2d(n):
L = spmatrix.ll_mat(n*n, n*n)
for i in range(n):
for j in range(n):
k = i + n*j
L[k,k] = 4
if i > 0:
def poisson2d_sym(n):
L = spmatrix.ll_mat_sym(n*n)
for i in range(n):
for j in range(n):
k = i + n*j
L[k,k] = 4
if i > 0:
def poisson2d_sym_blk(n):
L = spmatrix.ll_mat_sym(n*n)
I = spmatrix.ll_mat_sym(n)
P = spmatrix.ll_mat_sym(n)
for i in range(n):
I[i,i] = -1
for i in range(n):
P[i,i] = 4
if i > 0: P[i,i-1] = -1
for i in range(0, n*n, n):
src/c/s/csc-pysparse-1.1.1.4/examples/poisson_gmres.py csc-pysparse(Download)
def poisson2d(n):
L = spmatrix.ll_mat(n*n, n*n)
for i in range(n):
for j in range(n):
k = i + n*j
L[k,k] = 4
if i > 0:
def poisson2d_sym(n):
L = spmatrix.ll_mat_sym(n*n)
for i in range(n):
for j in range(n):
k = i + n*j
L[k,k] = 4
if i > 0:
def poisson2d_sym_blk(n):
L = spmatrix.ll_mat_sym(n*n)
I = spmatrix.ll_mat_sym(n)
P = spmatrix.ll_mat_sym(n)
for i in range(n):
I[i,i] = -1
for i in range(n):
P[i,i] = 4
if i > 0: P[i,i-1] = -1
for i in range(0, n*n, n):
src/j/a/jagpdf-HEAD/code/test/apitest/py/docexamples.py jagpdf(Download)
'0, 0, 255'
cs = doc.color_space_load(spec)
canvas.color_space('f', cs)
for i in range(3):
canvas.color('f', i)
canvas.rectangle(50, 540+(i+1)*60, 500, 55)
canvas.path_paint('f')
need to recalculate these to user space units."""
img_width = img.width() / img.dpi_x() * 72
img_height = img.height() / img.dpi_y() * 72
for x in range(7):
for y in range(15):
canvas.image(img, 90 + x * img_width, 100 + y * img_height)
#]
image. First, we will define an 80x80 checker pattern having one
bit per color."""
img_data = array.array('B')
for y in range(80):
for x in range(10):
img_data.append((y % 8) > 3 and 0xf0 or 0x0f)
"""` Note that we use [url_py_array] for efficient transfer of
"""` The following example is similar. It shows multi-line text,
each text is shown in a different color."""
canvas.text_start(50, 800)
for perc in range(10, 100, 10):
canvas.color('f', perc/100.0)
canvas.text('gray %d%%' % perc)
canvas.text_translate_line(5, -15)
canvas.text_translate_line(0, font.height())
"""` Finally, a justified text string can be achieved by
distributing `padding` evenly among spaces:"""
spaces = [i for i in range(len(txt)) if txt[i] == ' ']
num_spaces = len(spaces)
canvas.text(txt, num_spaces * [padding / num_spaces], spaces)
canvas.text_end()
elif alignment == 'centered':
canvas.text(line, [padding / 2.0], [0])
elif alignment == 'justified':
spaces = [i for i in range(len(line)) if line[i] == ' ']
num_spaces = len(spaces)
if not num_spaces or line == lines[-1][0]:
canvas.text(line)
src/n/i/nipy-HEAD/nipype/trunk/examples/spm_face_tutorial.py nipy(Download)
# Specify the subject directories
subject_list = ['M03953']
# Map field names to individual subject runs.
info = dict(func=[['RawEPI', 'subject_id', 5, ["_%04d"%i for i in range(6,357)]]],
struct=[['Structural', 'subject_id', 7, '']])
infosource = pe.Node(interface=util.IdentityInterface(fields=['subject_id']),
slice_timingref.num_slices = num_slices slice_timingref.time_repetition = TR slice_timingref.time_acquisition = TR - TR/float(num_slices) slice_timingref.slice_order = range(num_slices,0,-1) slice_timingref.ref_slice = num_slices/2 l1pipeline.inputs.preproc.smooth.fwhm = [8, 8, 8]
src/n/i/nipy-HEAD/nipype/trunk/examples/spm_auditory_tutorial.py nipy(Download)
# Specify the subject directories
subject_list = ['M00223']
# Map field names to individual subject runs.
info = dict(func=[['f', 'subject_id', 'f', 'subject_id', range(16,100)]],
struct=[['s', 'subject_id', 's', 'subject_id', 2]])
infosource = pe.Node(interface=util.IdentityInterface(fields=['subject_id']), name="infosource")
from nipype.interfaces.base import Bunch
subjectinfo = [Bunch(conditions=['Task'],
onsets=[range(6,84,12)],
durations=[[6]],
amplitudes=None,
tmod=None,
src/a/l/algopy-HEAD/experimental/examples/q-robust-OED.py algopy(Download)
def explicit_euler(x0,f,ts,p,q): N = size(ts) if isinstance(p[0],adolc.adouble): x = array([adolc.adouble(0) for m in range(Nm)]) else: x = zeros(N) x[0] = x0 for n in range(1,N):
p[0]-= 3.; p[1] -= 2. # taping F av = array([adolc.adouble(0) for i in range(Nv)]) y = zeros(Nm) adolc.trace_on(1) av[0].is_independent(p[0]) av[1].is_independent(p[1]) av[2].is_independent(q[0]) ay = F(av[:Np],av[Np:],ts,Sigma,etas) for m in range(Nm):
adolc.trace_off() # taping measurement_model av = array([adolc.adouble(0) for i in range(Nv)]) y = zeros(Nm) adolc.trace_on(2) av[0].is_independent(p[0]) av[1].is_independent(p[1]) av[2].is_independent(q[0]) ax = explicit_euler(av[0],f,ts,av[:Np],av[Np:]) ay = measurement_model(ax, av[:Np],av[Np:]) for m in range(Nm):
J = zeros((DM+1,1,Nm,Np)) # Taylor series of degree DM has DM+1 taylor coefficients (i.e. count also the zero-derivative) qbar_rays = zeros((NJq,Nq,DM+1)) for nq in range(NJq): # 1: evaluation of J # here, we have to use nested interpolation
# we use here formula (13) of the paper "Evaluating higher derivative tensors by forward propagation of univariate Taylor series" for np in range(Np): # each column of J for dm in range(DM+1): I = array([1,dm]) K = zeros((dm+1,2),dtype=int) K[:,0] = 1 K[:,1] = range(dm+1)
tmp = adolc.hos_forward(1,v,V,0)[1] J[dm,0,:,np] += (-1)**multi_index_abs( I - k) * multi_index_binomial(I,k) * tmp[:,dm] scale_factor = array([1./prod(range(1,d+1)) for d in range(DM+1)]) for dm in range(DM+1): J[dm,:,:,:] *= scale_factor[dm]
## 4: reverse evaluation of J vbar = zeros(Nv) dJ = zeros((Nq,DM+1)) # taylor coefficients for one direction in q for np in range(Np): # each column of J for dm in range(DM+1): I = array([1,dm]) K = zeros((dm+1,2),dtype=int) K[:,0] = 1 K[:,1] = range(dm+1)
# U is a (Q,M,D) array # Jbar is a (D,M,Np) array U = zeros((1,Nm,keep)) for d in range(dm+1): U[0,:,d] = Jbar[d,:,np] #print 'U=',U Z = adolc.hov_ti_reverse(1,U)[0] #print 'Z=',Z #J[dm,0,:,np] += (-1)**multi_index_abs( I - k) * multi_index_binomial(I,k) * tmp[:,dm] #print shape(Z[0,:,:]) #exit() #print Z[0,:,dm+1] tmp = 1./prod(range(1,dm+2)) * (-1)**multi_index_abs( I - k) * multi_index_binomial(I,k) * Z[0,Np:,dm+1]
# use interpolation to build all PHI^(dm) 0<= dm <= DM derivative_tensor_list = [] for dm in range(DM+1): derivative_tensor = numpy.zeros([Nq for i in range(dm+1)]) I = generate_multi_indices(Nq,dm) d = sum(I[0,:]) NI = shape(I)[0] NJq = shape(Jq)[0] for ni in range(NI): for nj in range(NJq): derivative_tensor[tuple([0 for i in range(dm+1)])] += gamma(I[ni,:], Jq[nj,:]) * qbar_rays[nj,:,d]
src/c/a/casadi-HEAD/trunk/examples/python/vdp_multiple_shooting.py casadi(Download)
U_min = [] U_max = [] U_init = [] for i in range(NS): U.append(V[i]) U_min.append(u_min) U_max.append(u_max)
X_min = [] X_max = [] X_init = [] for i in range(NS): X += [V[NU+i*3 : NU+(i+1)*3]] X_init += [x_init, y_init, L_init] if i==NS-1:
g_max = [] # Build up a graph of integrator calls for k in range(NS): # call the integrator [XF,XP,Z] = I.call([T0[k],TF[k],X0,U[k],XP,Z])
v_opt = solver.output(NLP_X_OPT) u_opt = v_opt[0:NU] X_opt = v_opt[NU:] x_opt = [X_opt[k] for k in range(0,3*NS,3)] y_opt = [X_opt[k] for k in range(1,3*NS,3)] l_opt = [X_opt[k] for k in range(2,3*NS,3)]
Previous 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 Next