[pymvpa] problem with reverse mapper

Serin Atiani, Dr serin.atiani at mail.mcgill.ca
Thu Apr 30 15:56:14 UTC 2015

Thanks for your response Nick

I tried what you suggested, 
 revtest=np.arange(100, 100+fds_p.nfeatures)[np.newaxis]

but that also returns a vector, so the error takes place again. If what needs to be passed is a matrix, and not a vector, why do we use the np.arange step? that seems just to create a range for processing, am I right? 

Below are the commands executed again. Please let me know what you think

>>> print fds_p.a.mapper
<Chain: <Flatten>-<StaticFeatureSelection>-<PolyDetrend: ord=1>-<ZScore>-<Fx: fx=mean>>
>>> fds_p.nfeatures
>>> fds_p.nsamples
>>> revtest=np.arange(100, 100+fds_p.nfeatures)[np.newaxis]
>>> revtest.shape
(1, 500)
>>> rmapped=fds_p.a.mapper.reverse1(revtest)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/mvpa2/mappers/base.py", line 343, in reverse1
    mp = self[:-1 * i].reverse(mp)
  File "/usr/lib/python2.7/dist-packages/mvpa2/mappers/base.py", line 308, in reverse
    mp = m.reverse(mp)
  File "/usr/lib/python2.7/dist-packages/mvpa2/mappers/base.py", line 238, in reverse
    return self._reverse_data(data)
  File "/usr/lib/python2.7/dist-packages/mvpa2/featsel/base.py", line 149, in _reverse_data
    mapped[:, self._slicearg] = data
ValueError: array is not broadcastable to correct shape

From: Nick Oosterhof <n.n.oosterhof at googlemail.com>
To: Development and support of PyMVPA
        <pkg-exppsy-pymvpa at lists.alioth.debian.org>
Subject: Re: [pymvpa] problem with reverse mapper
Message-ID: <9974D6B3-E8B0-4FA9-8B85-545E1F83D0E8 at googlemail.com>
Content-Type: text/plain; charset=windows-1252

On 22 Apr 2015, at 15:22, Serin Atiani, Dr <serin.atiani at mail.mcgill.ca> wrote:

> I am doing basic analysis, mostly following the steps of the tutorial. I am trying to reverse the mappers in order to project the features I am interested in back into Nifti file. I am getting the error below. Any thoughts what I am doing wrong?
>>>> print fds_p.a.mapper
> <Chain: <Flatten>-<StaticFeatureSelection>-<PolyDetrend: ord=1>-<ZScore>-<Fx: fx=mean>>
>>>> fds_p.nfeatures
> 500
>>>> revtest=np.arange(100, 100+fds_p.nfeatures)

The size of revtest does not match that of what is expected by the mapper, because it?s shape should be (N,fds_p.nfeatures) [where N is the number of samples], i.e. a matrix with 100 columns. np.arange(100,100+fds_p.nfeatures) produces a vector with shape (fds_p.nfeatures,).

Can you try:

revtest=np.arange(100, 100+fds_p.nfeatures)[np.newaxis]

More information about the Pkg-ExpPsy-PyMVPA mailing list