code: def _save_sensitivities(self, directory):
          
          print('saving sensitivities')
          digits = int(np.ceil(np.log10(self.configs.configs.shape[0])))
          for i in range(0, self.configs.configs.shape[0]):
              sens_data, meta_data = self.get_sensitivity(i)
              filename_raw = 'sens{0:0' + '{0}'.format(digits) + '}.dat'
              filename = directory + os.sep + filename_raw.format(i + 1)
  
              grid_xz = self.grid.get_element_centroids()
              all_data = np.vstack((
                  grid_xz[:, 0],
                  grid_xz[:, 0],
                  sens_data[0],
                  sens_data[1],
              )).T
              with open(filename, 'wb') as fid:
                  fid.write(bytes(
                      '{0} {1}\n'.format(meta_data[0], meta_data[1]),
                      'utf-8'
                  ))
                  np.savetxt(fid, all_data)
docs: save sensitivities to a directory