def unflatten_vec(doc_vector, ndims=300):
    """
    Turn a document vector back into an fft array. Roughly speaking,
    this is the inverse of `flatten_fft`. Note that we need to know
    the number of dimensions to get the right shape for the array.

    The resulting array is a 2-d array of complex numbers, as expected
    by `flatten_fft`.
    """

    array = doc_vector.reshape(ndims, -1)
    real = array[:, ::2]
    imag = array[:, 1::2]
    return real + imag * 1j