def reshapeToBroadcast(what, ref):
    """ expand the 1d array 'what' to allow broadbasting to match 
      multidimentional array 'ref'. The two arrays have to same the same 
      dimensions along the first axis
  """
    if what.shape == ref.shape:
        return what
    assert what.shape[0] == ref.shape[0
        ], 'automatic reshaping requires same first dimention'
    shape = [ref.shape[0]] + [1] * (ref.ndim - 1)
    return what.reshape(shape)
