def matrix_to_4dvolume(arr, mask, order='<STR_LIT:C>'):
if mask.dtype != np.bool:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if arr.ndim != <NUM_LIT:2>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if mask.sum() != arr.shape[<NUM_LIT:0>]:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(mask.sum(), arr.shape))<EOL><DEDENT>data = np.zeros(mask.shape + (arr.shape[<NUM_LIT:1>],), dtype=arr.dtype,<EOL>order=order)<EOL>data[mask, :] = arr<EOL>return data<EOL>
Transform a given vector to a volume. This is a reshape function for
    4D flattened masked matrices where the second dimension of the matrix
    corresponds to the original 4th dimension.

    Parameters
    ----------
    arr: numpy.array
        2D numpy.array

    mask: numpy.ndarray
        Mask image. Must have 3 dimensions, bool dtype.

    dtype: return type
        If None, will get the type from vector

    Returns
    -------
    data: numpy.ndarray
        Unmasked data.
        Shape: (mask.shape[0], mask.shape[1], mask.shape[2], X.shape[1])