def recompose_xfm(in_bval, in_xfms):
 import numpy as np
 import os.path as op
 bvals = np.loadtxt(in_bval)
 out_matrix = np.array(([np.eye(4)] * len(bvals)))
 xfms = iter([np.loadtxt(xfm) for xfm in in_xfms])
 out_files = []
 for (i, b) in enumerate(bvals):
  if (b == 0.0):
   mat = np.eye(4)
  else:
   mat = next(xfms)
  out_name = op.abspath((u'eccor_%04d.mat' % i))
  out_files.append(out_name)
  np.savetxt(out_name, mat)
 return out_files

def recompose_xfm ( in_bval , in_xfms ) : import numpy as np import os . path as op bvals = np . loadtxt ( in_bval ) out_matrix = np . array ( ( [ np . eye ( 4 ) ] * len ( bvals ) ) ) xfms = iter ( [ np . loadtxt ( xfm ) for xfm in in_xfms ] ) out_files = [ ] for ( i , b ) in enumerate ( bvals ) : if ( b == 0.0 ) : mat = np . eye ( 4 ) else : mat = next ( xfms ) out_name = op . abspath ( ( u'eccor_%04d.mat' % i ) ) out_files . append ( out_name ) np . savetxt ( out_name , mat ) return out_files
insert identity transformation matrices in b0 volumes to build up a list .