def dict_to_vec(val_dict, var_offsets, var_sizes, vec_len):
 vector = np.zeros(vec_len)
 for (id_, value) in val_dict.items():
  size = var_sizes[id_]
  offset = var_offsets[id_]
  for col in range(size[1]):
   if np.isscalar(value):
    vector[offset:(size[0] + offset)] = value
   else:
    vector[offset:(size[0] + offset)] = np.squeeze(value[:, col])
   offset += size[0]
 return vector

def dict_to_vec ( val_dict , var_offsets , var_sizes , vec_len ) : vector = np . zeros ( vec_len ) for ( id_ , value ) in val_dict . items ( ) : size = var_sizes [ id_ ] offset = var_offsets [ id_ ] for col in range ( size [ 1 ] ) : if np . isscalar ( value ) : vector [ offset : ( size [ 0 ] + offset ) ] = value else : vector [ offset : ( size [ 0 ] + offset ) ] = np . squeeze ( value [ : , col ] ) offset += size [ 0 ] return vector
converts a map of variable id to value to a vector .