Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/nipyPublic

Commit6583e52

Browse files
Apply ruff/Perflint rule PERF401
PERF401 Use a list comprehension to create a transformed list
1 parent2c1cf76 commit6583e52

File tree

12 files changed

+25
-49
lines changed

12 files changed

+25
-49
lines changed

‎examples/interfaces/process_ds105.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,7 @@ def process_subject(ddef, study_def, ana_def):
308308

309309

310310
defget_subjects(data_path,subj_ids,study_def,ana_def):
311-
ddefs= []
312-
forsubj_idinsubj_ids:
313-
ddefs.append(get_fdata(data_path,subj_id))
314-
returnddefs
311+
return [get_fdata(data_path,subj_id)forsubj_idinsubj_ids]
315312

316313

317314
defmain():

‎nipy/algorithms/clustering/gmm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,8 +848,7 @@ def show_components(self, x, gd, density=None, mpaxes=None):
848848
fontsize=12)
849849

850850
legend= ['data']
851-
forkinrange(self.k):
852-
legend.append('component %d'% (k+1))
851+
legend.extend(f'component{k}'forkinrange(1,self.k+1))
853852
l=ax.legend(tuple(legend))
854853
fortinl.get_texts():
855854
t.set_fontsize(12)

‎nipy/algorithms/clustering/hierarchical_clustering.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,8 @@ def list_of_subtrees(self):
221221
way such that parent[i]>i for all i
222222
Only the leaves are listeed, not the subtrees themselves
223223
"""
224-
lst= []
224+
lst= [np.array([],np.int_)foriinrange(self.V)]
225225
n=np.sum(self.isleaf())
226-
foriinrange(self.V):
227-
lst.append(np.array([],np.int_))
228226
foriinrange(n):
229227
lst[i]=np.array([i],np.int_)
230228
foriinrange(self.V-1):

‎nipy/algorithms/graph/graph.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,9 +1221,7 @@ def left_incidence(self):
12211221
list[[e.0.0, .., e.0.i(0)], .., [e.V.0, E.V.i(V)]] where e.i.j is
12221222
the set of edge indexes so that e.i.j[0] = i
12231223
"""
1224-
linc= []
1225-
foriinrange(self.V):
1226-
linc.append([])
1224+
linc= [[]foriinrange(self.V)]
12271225
foreinrange(self.E):
12281226
i=self.edges[e,0]
12291227
a=linc[i]
@@ -1240,9 +1238,7 @@ def right_incidence(self):
12401238
list[[e.0.0, .., e.0.i(0)], .., [e.V.0, E.V.i(V)]] where e.i.j is
12411239
the set of edge indexes so that e.i.j[1] = i
12421240
"""
1243-
rinc= []
1244-
foriinrange(self.V):
1245-
rinc.append([])
1241+
rinc= [[]foriinrange(self.V)]
12461242
foreinrange(self.E):
12471243
i=self.edges[e,1]
12481244
a=rinc[i]

‎nipy/algorithms/statistics/formula/formulae.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,10 @@ def getparams(expression):
302302
expression=expression.reshape((np.prod(expression.shape),))
303303
forterminexpression:
304304
atoms=atoms.union(sympy.sympify(term).atoms())
305-
params= []
306-
foratominatoms:
307-
ifisinstance(atom,sympy.Symbol)andnotis_term(atom):
308-
params.append(atom)
309-
params.sort(key=default_sort_key)
305+
params=sorted((atom
306+
foratominatoms
307+
ifisinstance(atom,sympy.Symbol)andnotis_term(atom)),
308+
key=default_sort_key)
310309
returnparams
311310

312311

@@ -330,11 +329,8 @@ def getterms(expression):
330329
expression=expression.reshape((np.prod(expression.shape),))
331330
foreinexpression:
332331
atoms=atoms.union(e.atoms())
333-
terms= []
334-
foratominatoms:
335-
ifis_term(atom):
336-
terms.append(atom)
337-
terms.sort(key=default_sort_key)
332+
terms=sorted((atomforatominatomsifis_term(atom)),
333+
key=default_sort_key)
338334
returnterms
339335

340336

‎nipy/algorithms/statistics/models/tests/test_anova.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@
8585
#
8686
# http://www-stat.stanford.edu/~jtaylo/courses/stats191/data/kidney.table
8787

88-
D= []
89-
forrowinStringIO(data):
90-
D.append([float(val)forvalinrow.split()])
88+
D= [[float(val)forvalinrow.split()]forrowinStringIO(data)]
9189
D=make_recarray(D, ['Days','Duration','Weight','ID'])
9290

9391
# Create the categorical regressors, known as Factors

‎nipy/algorithms/statistics/tests/test_intrinsic_volumes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ def randorth(p=10):
2828

2929
defbox(shape,edges):
3030
data=np.zeros(shape)
31-
sl= []
32-
foriinrange(len(shape)):
33-
sl.append(slice(edges[i][0],edges[i][1],1))
31+
sl= [slice(edges[i][0],edges[i][1],1)foriinrange(len(shape))]
3432
data[tuple(sl)]=1
3533
returndata.astype(np.int_)
3634

‎nipy/algorithms/utils/matrices.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ def full_rank(X, r=None):
105105
V,D,U=spl.svd(X,full_matrices=0)
106106
order=np.argsort(D)
107107
order=order[::-1]
108-
value= []
109-
foriinrange(r):
110-
value.append(V[:,order[i]])
108+
value= [V[:,order[i]]foriinrange(r)]
111109
returnnp.asarray(np.transpose(value)).astype(np.float64)
112110

113111

‎nipy/interfaces/spm.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,4 @@ def fname_presuffix(fname, prefix='', suffix='', use_ext=True):
9797

9898

9999
deffnames_presuffix(fnames,prefix='',suffix=''):
100-
f2= []
101-
forfnameinfnames:
102-
f2.append(fname_presuffix(fname,prefix,suffix))
103-
returnf2
100+
return [fname_presuffix(fname,prefix,suffix)forfnameinfnames]

‎nipy/io/nifti_ref.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ def nipy2nifti(img, data_dtype=None, strict=None, fix0=True):
345345
# Use list() to get .index method for python < 2.6
346346
input_names=list(coordmap.function_domain.coord_names)
347347
spatial_names=input_names[:3]
348-
dim_infos= []
349-
forfpsin'freq','phase','slice':
350-
dim_infos.append(
351-
spatial_names.index(fps)iffpsinspatial_nameselseNone)
348+
dim_infos= [
349+
spatial_names.index(fps)iffpsinspatial_nameselseNone
350+
forfpsin ('freq','phase','slice')
351+
]
352352
hdr.set_dim_info(*dim_infos)
353353
# Set units without knowing time
354354
hdr.set_xyzt_units(xyz='mm')

‎nipy/labs/utils/reproducibility_measures.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ def get_cluster_position_from_thresholded_map(stat_map, domain, thr=3.0,
128128
coord=thresholded_domain.get_coord()
129129

130130
# get the barycenters
131-
baryc= []
132-
foriinrange(label.max()+1):
133-
ifnp.sum(label==i)>=csize:
134-
baryc.append(np.mean(coord[label==i],0))
131+
baryc= [
132+
np.mean(coord[label==i],0)
133+
foriinrange(label.max()+1)
134+
ifnp.sum(label==i)>=csize
135+
]
135136

136137
iflen(baryc)==0:
137138
returnNone

‎nipy/modalities/fmri/design_matrix.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ def _make_drift(drift_model, frametimes, order=1, hfcut=128.):
131131
drift=_blank_drift(frametimes)
132132
else:
133133
raiseNotImplementedError(f"Unknown drift model{drift_model!r}")
134-
names= []
135-
forkinrange(drift.shape[1]-1):
136-
names.append('drift_%d'% (k+1))
134+
names= [f'drift_{k}'forkinrange(1,drift.shape[1])]
137135
names.append('constant')
138136
returndrift,names
139137

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp