[Neuroimaging] what's the problem??????

avi.e.gross at gmail.com avi.e.gross at gmail.com
Thu Jul 14 13:24:23 EDT 2022


That is more detailed, Nati, albeit I may not still understand.

 

You are working on a detailed project you may have some understanding of and getting stuck. But the people you ask for help do not have your info and, worse, your code seems full of blunders based on making assumptions, so reading it can give us a headache when we still have no idea what you want to do and what you want to do it to.

 

So let me make sure what I think you said and am replying to, is what you want. My guess is not.

 

It sounds like you already have a dictionary of size N that you read in from a file I have no access to and cannot see the contents but presumably contains two columns that can be converted into dictionary format. 

 

My first guess was you had another list of something also of length N stored in Difumo_names and wanted to substitute those new keys for the old ones. If the two are of the same length that should be doable, albeit older versions of dictionaries in Python did not guarantee the order of the contents. But reading the old code and your new stuff together does not lead me to assume this is the scenario. Your English may not be up to explaining as your short phrases seem to not mean what we expect.

 

Your code shown (way below) does not explain what "Difumo_names" used in quotes means but your code suggests it is meant as a SINGLE key as you use it like

 

b=a["Difumo_names"]

 

But is there any guarantee the dictionary has anything with that key? You may want to use a form that fails better such as:

 

b=a.get("Difumo_names"],-1)

 

That fails by assigning whatever default you replace “-1” with.

 

Just BTW, it might be a good idea to use names longer and more meaningful than “a” and “b” as following your code is harder when I have no idea what anything is about or for.

 

I, however, think your use of “b” later in your code makes no sense with this interpretation. What is stored in b if done as above is the arbitrary value in a[("Difumo_names"] which could be many things, including a list, but your code never explains what it is. So later you never use b in the code shown but several times use the construct below.

 

As part of a function call, one argument is:

 

labels=list(a["Difumo_names"].values())

 

The above SUGGESTS that you have a dictionary in a dictionary. Meaning, the dictionary called “a” has a key/value pair with the key being "Difumo_names"]” and the value being another dictionary that you can ask for the values alone and then combine them into a list.

 

But is this true? You need to know and explain what your dictionary contains and whether labels.to_dict() properly is able to read in a CSV and not only make a dictionary from it but make some of the values into sub-dictionaries. If not, you might need a better way to make your data structure.

 

Now, IF (and I am beyond guessing at this point) there is supposed to be a data structure in the value at a["Difumo_names"] that you want to be a dictionary, but it is now stored as something like a character string, then you need to find a way to convert it to a dictionary before using it like a dictionary.

 

I end by saying I have no clear idea what you want and expect at each step in your program. My suggestion is you rewrite your code to carefully print out info as it goes along and verify if what you are seeing makes sense at every step. Specifically, see what all the keys an values in “a” are. And at the REPL, play around and try typing in some code and see if it fails and what error messages you see. If some of your assumptions are wrong, they need fixing in that place and not by asking mysterious questions here from people who cannot see most of the picture.

 

 

 

 

From: נתי שטרן <nsh531 at gmail.com> 
Sent: Thursday, July 14, 2022 1:50 AM
To: avi.e.gross at gmail.com; python-list at python.org; Neuroimaging analysis in Python <neuroimaging at python.org>
Subject: Re: [Neuroimaging] what's the problem??????

 

Instead of numbers, I want to enter as indexes the names of the Index as being in b variable:

 labels = pd.read_csv("C:/Users/Administrator/Desktop/64/64/labels_64_dictionary.csv")

    a=labels.to_dict()

    b=a["Difumo_names"]

 

‫בתאריך יום ה׳, 14 ביולי 2022 ב-7:44 מאת <‪ <mailto:avi.e.gross at gmail.com> avi.e.gross at gmail.com‏>:

Nati,

I know you think you are communicating.

        שטרן >> I want to swap indexes of dict

When you say SWAP, do you mean replace the index with something else, or swap the key and value or something entirely else?

You have not shared an example of what is in your dictionary, but say it is:

myDict = {1:"a", 2:"b", 3:"c"}

invDict = { value:key for key, value in myDict.items() }

print(myDict)
print(invDict)


The above prints out:

print(myDict)
{1: 'a', 2: 'b', 3: 'c'}

print(invDict)
{'a': 1, 'b': 2, 'c': 3}

It obviously generalizes only for dictionaries where all values are unique. And you can obviously save the results back into the same variable if you wish. The above comprehension may, of course, not be what you want as swapping indexes with <UNSPECIFIED> may not mean anything to us trying to help.

Avi (a שטרן on my mother's side.)


-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com at python.org <mailto:gmail.com at python.org> > On Behalf Of ??? ????
Sent: Thursday, July 14, 2022 12:19 AM
To: David Welch <david.m.welch at gmail.com <mailto:david.m.welch at gmail.com> >; Neuroimaging analysis in Python <neuroimaging at python.org <mailto:neuroimaging at python.org> >; python-list at python.org <mailto:python-list at python.org> 
Subject: Re: [Neuroimaging] what's the problem??????

I want to swap indexes of dict

בתאריך יום ד׳, 13 ביולי 2022, 21:51, מאת David Welch ‏<
david.m.welch at gmail.com <mailto:david.m.welch at gmail.com> >:

>
>>    - Describe the research *you did* to try and understand the problem
>>    *before* you asked the question.
>>    - Describe the diagnostic steps *you took* to try and pin down the
>>    problem yourself *before* you asked the question.
>>
>>
> On Wed, Jul 13, 2022 at 1:47 PM David Welch <david.m.welch at gmail.com <mailto:david.m.welch at gmail.com> >
> wrote:
>
>> From http://catb.org/~esr/faqs/smart-questions.html#beprecise:
>>
>>> Be precise and informative about your problem
>>>
>>>    -
>>>
>>>    Describe the symptoms of your problem or bug carefully and clearly.
>>>    -
>>>
>>>    Describe the environment in which it occurs (machine, OS,
>>>    application, whatever). Provide your vendor's distribution and release
>>>    level (e.g.: “Fedora Core 7”, “Slackware 9.1”, etc.).
>>>    -
>>>
>>>    Describe the research you did to try and understand the problem
>>>    before you asked the question.
>>>    -
>>>
>>>    Describe the diagnostic steps you took to try and pin down the
>>>    problem yourself before you asked the question.
>>>    -
>>>
>>>    Describe any possibly relevant recent changes in your computer or
>>>    software configuration.
>>>    -
>>>
>>>    If at all possible, provide a way to *reproduce the problem in a
>>>    controlled environment*.
>>>
>>> Do the best you can to anticipate the questions a hacker will ask, 
>>> and answer them in advance in your request for help.
>>>
>>> Giving hackers the ability to reproduce the problem in a controlled 
>>> environment is especially important if you are reporting something 
>>> you think is a bug in code. When you do this, your odds of getting a 
>>> useful answer and the speed with which you are likely to get that 
>>> answer both improve tremendously.
>>>
>>> Simon Tatham has written an excellent essay entitled How to Report 
>>> Bugs Effectively 
>>> <http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>. I strongly recommend that you read it.
>>>
>>>
>>
>> ---------- Forwarded message ---------
>> From: נתי שטרן <nsh531 at gmail.com <mailto:nsh531 at gmail.com> >
>> Date: Wed, Jul 13, 2022 at 1:36 PM
>> Subject: Re: [Neuroimaging] what's the problem??????
>> To: Neuroimaging analysis in Python <neuroimaging at python.org <mailto:neuroimaging at python.org> >, < 
>> python-list at python.org <mailto:python-list at python.org> >
>>
>>
>> I want to set dict
>>
>> בתאריך יום ד׳, 13 ביולי 2022, 20:47, מאת נתי שטרן ‏<nsh531 at gmail.com <mailto:nsh531 at gmail.com> >:
>>
>>> CODE:
>>>
>>> for nii in os.listdir("c:/users/administrator/desktop/nii"):
>>>
>>>     from nilearn import plotting
>>>     from nilearn import datasets
>>>     atlas = datasets.fetch_atlas_msdl()
>>>     # Loading atlas image stored in 'maps'
>>>     atlas_filename =
>>> "C:/Users/Administrator/Desktop/64/64/2mm/maps.nii.gz"
>>>     # Loading atlas data stored in 'labels'
>>>     labels = pd.read_csv(
>>> "C:/Users/Administrator/Desktop/64/64/labels_64_dictionary.csv")
>>>     a=labels.to_dict()
>>>     b=a["Difumo_names"]
>>>     from nilearn.maskers import NiftiMapsMasker
>>>     masker = NiftiMapsMasker(maps_img=atlas_filename, standardize=True,
>>>                             memory='nilearn_cache', verbose=5)
>>>
>>>     time_series = masker.fit_transform(
>>> "c:/users/administrator/desktop/nii/"+nii)
>>>     try:
>>>         from sklearn.covariance import GraphicalLassoCV
>>>     except ImportError:
>>>         # for Scitkit-Learn < v0.20.0
>>>         from sklearn.covariance import GraphLassoCV as 
>>> GraphicalLassoCV
>>>
>>>     estimator = GraphicalLassoCV()
>>>     estimator.fit(time_series)
>>> # Display the covariancec
>>>     aas={}
>>>     jsa=0
>>>     for i in estimator.covariance_:
>>>         r=list(a["Difumo_names"].values())[jsa]
>>>         jsa=jsa+1
>>>         a=dict()
>>>
>>>
>>>         for x in range(64):
>>>             g=list(a["Difumo_names"].values())[x]
>>>
>>>     print(aas)
>>>     t=   nilearn.plotting.plot_img(estimator.covariance_, labels=list(a[
>>> "Difumo_names"].values()),
>>>                         figure=(9, 7), vmax=1, vmin=-1,
>>>                         title='Covariance')# The covariance can be 
>>> found at estimator.covariance_
>>>
>>> # The covariance can be found at estimator.covariance_
>>>     t2=  nilearn.plotting.plot_matrix(estimator.covariance_, 
>>> labels=list (a["Difumo_names"].values()),
>>>                         figure=(9, 7), vmax=1, vmin=-1,
>>>                         title='Covariance')
>>>
>>>
>>>
>>> --
>>> <https://netanel.ml>
>>>
>> _______________________________________________
>> Neuroimaging mailing list
>> Neuroimaging at python.org <mailto:Neuroimaging at python.org> 
>> https://mail.python.org/mailman/listinfo/neuroimaging
>>
>
--
https://mail.python.org/mailman/listinfo/python-list




 

-- 

 <https://netanel.ml/> 



More information about the Python-list mailing list