Skip to content

Commit 370c811

Browse files
Replace genfromtxt with loadtxt
This is much faster (it reduced the running time for the cifti2 tests from 51 seconds to 15 seconds on my computer). The main disadvantage of loadtxt is that it can not handle missing values, but there should be no missing values anyway
1 parent 0f947a4 commit 370c811

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

nibabel/cifti2/parse_cifti2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,28 +517,28 @@ def flush_chardata(self):
517517
# conversion to numpy array
518518
c = BytesIO(data.strip().encode('utf-8'))
519519
vertices = self.struct_state[-1]
520-
vertices.extend(np.genfromtxt(c, dtype=np.int))
520+
vertices.extend(np.loadtxt(c, dtype=np.int))
521521
c.close()
522522

523523
elif self.write_to == 'VoxelIndices':
524524
# conversion to numpy array
525525
c = BytesIO(data.strip().encode('utf-8'))
526526
parent = self.struct_state[-1]
527-
parent.voxel_indices_ijk.extend(np.genfromtxt(c, dtype=np.int).reshape(-1, 3))
527+
parent.voxel_indices_ijk.extend(np.loadtxt(c, dtype=np.int).reshape(-1, 3))
528528
c.close()
529529

530530
elif self.write_to == 'VertexIndices':
531531
# conversion to numpy array
532532
c = BytesIO(data.strip().encode('utf-8'))
533533
index = self.struct_state[-1]
534-
index.extend(np.genfromtxt(c, dtype=np.int))
534+
index.extend(np.loadtxt(c, dtype=np.int))
535535
c.close()
536536

537537
elif self.write_to == 'TransformMatrix':
538538
# conversion to numpy array
539539
c = BytesIO(data.strip().encode('utf-8'))
540540
transform = self.struct_state[-1]
541-
transform.matrix = np.genfromtxt(c, dtype=np.float)
541+
transform.matrix = np.loadtxt(c, dtype=np.float)
542542
c.close()
543543

544544
elif self.write_to == 'Label':

0 commit comments

Comments
 (0)