Skip to content

Commit 13c2cab

Browse files
committed
added squeeze to split
1 parent 35c9f46 commit 13c2cab

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

nipype/interfaces/utility.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ class SplitInputSpec(BaseInterfaceInputSpec):
252252
desc='list of values to split')
253253
splits = traits.List(traits.Int, mandatory=True,
254254
desc='Number of outputs in each split - should add to number of inputs')
255+
squeeze = traits.Bool(False, usedefault=True,
256+
desc='unfold one-element splits removing the list')
255257

256258

257259
class Split(IOBase):
@@ -290,7 +292,10 @@ def _list_outputs(self):
290292
splits.extend(self.inputs.splits)
291293
splits = np.cumsum(splits)
292294
for i in range(len(splits) - 1):
293-
outputs['out%d' % (i + 1)] = np.array(self.inputs.inlist)[splits[i]:splits[i + 1]].tolist()
295+
val = np.array(self.inputs.inlist)[splits[i]:splits[i + 1]].tolist()
296+
if self.inputs.squeeze and len(val) == 1:
297+
val = val[0]
298+
outputs['out%d' % (i + 1)] = val
294299
return outputs
295300

296301

0 commit comments

Comments
 (0)