[Neuroimaging] writing a 1D python array to 3D Nifti file

Christophe Pallier christophe at pallier.org
Tue May 10 01:45:47 EDT 2022


Well there  are scenarios where it totally makes sense to transform to 1D,
for example to use some sklearn functions that require vectors.

In such cases, I find that nilearn's niftimaskers are a simple tool to go
from 3d (or 4d) to 1d (or 2d), and vice versa.



On Tue, May 10, 2022, 00:03 Yaroslav Halchenko <lists at onerussian.com> wrote:

> I would have recommended to "go back" and to avoid explicit flattening /
> re-3ding etc.  Why you had to go into 1D?
>
> PS reminded me about an excellent sci-fi book "Three body problem" where
> poor folks had to dry up to survive through apocalypses (and being
> rolled up and stored deep underground) and then rehydrate, so in
> effect do 3D -> 2D -> 3D  ;)  not sure how they survived ;)
>
> On Mon, 09 May 2022, Lorenzo Pini wrote:
>
> >    Dear experts,
> >    I uploaded a 3D nifti file with nibabel, transformed it into a 1D
> array
> >    and performed some transformations. My final 1D array has size 902629
> (MNI
> >    vector space).
> >    Now, I would like to convert this 1D array back to a 3D nifti image.
> Any
> >    advice to perform this operation?
> >    Thankx,
> >    L
>
> > _______________________________________________
> > Neuroimaging mailing list
> > Neuroimaging at python.org
> > https://mail.python.org/mailman/listinfo/neuroimaging
>
>
> --
> Yaroslav O. Halchenko
> Center for Open Neuroscience     http://centerforopenneuroscience.org
> Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755
> WWW:   http://www.linkedin.com/in/yarik
>
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/neuroimaging/attachments/20220510/3a680136/attachment.html>


More information about the Neuroimaging mailing list