Inverse_transform error: X must be of shape (samples, features)

I have about 20 subjects with and without ASD fetch from ABIDE using nilearn. Using fit_transform of NiftiMasker object, we mask the images and then use FastICA to get the independent components. Trying to invert the masking procedure using inverse_transform throws the error ‘X must be of shape…’

Here is the code:
pitt_typical_ds=fetch_abide_pcp(SUB_ID=[50030, 50031])
from nilearn.input_data import NiftiMasker

masker = NiftiMasker(smoothing_fwhm=8, memory='nilearn_cache', memory_level=1, mask_strategy='epi', 

for typical in pitt_typical_ds.func_preproc:

ica=FastICA(n_components=10, random_state=42)
for typical in typical_timeseries:

    # Normalize estimated components, for thresholding to make sense
    components_masked -= components_masked.mean(axis=0)
    components_masked /= components_masked.std(axis=0)
    # Threshold
    import numpy as np
    components_masked[np.abs(components_masked) < .8] = 0

    # Now invert the masking operation, going back to a full 3D
    # representation
    component_img = masker.inverse_transform(components_masked)

inverse_transform expects 2D data. It should suffice to do the following:

component_img = masker.inverse_transform([components_masked])
1 Like

Thank you very much ! I wish I had see that earlier !