Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9080417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:04:18+00:00 2026-06-16T20:04:18+00:00

I have a nested dictionary containing a bunch of data on a number of

  • 0

I have a nested dictionary containing a bunch of data on a number of different objects (where I mean object in the non-programming sense of the word). The format of the dictionary is allData[i][someDataType], where i is a number designation of the object that I have data on, and someDataType is a specific data array associated with the object in question.

Now, I have a function that I have defined that requires a particular data array for a calculation to be performed for each object. The data array is called cleanFDF. So I feed this to my function, along with a bunch of other things it requires to work. I call it like this:

rm.analyze4complexity(allData[i]['cleanFDF'], other data, other data, other data)

Inside the function itself, I straight away re-assign the cleanFDF data to another variable name, namely clFDF. I.e. The end result is:

clFDF = allData[i]['cleanFDF']

I then have to zero out all of the data that lies below a certain threshold, as such:

clFDF[ clFDF < threshold ] = 0

OK – the function works as it is supposed to. But now when I try to plot the original cleanFDF data back in the main script, the entries that got zeroed out in clFDF are also zeroed out in allData[i]['cleanFDF']. WTF? Obviously something is happening here that I do not understand.

To make matters even weirder (from my point of view), I’ve tried to do a bodgy kludge to get around this by ‘saving’ the array to another variable before calling the function. I.e. I do

saveFDF = allData[i]['cleanFDF']

then run the function, then update the cleanFDF entry with the ‘saved’ data:

allData[i].update( {'cleanFDF':saveFDF} )

but somehow, simply by performing clFDF[ clFDF < threshold ] = 0 within the function modifies clFDF, saveFDF and allData[i]['cleanFDF'] in the main friggin’ script, zeroing out all the entires at the same array indexes! It is like they are all associated global variables somehow, but I’ve made no such declarations anywhere…

I am a hopeless Python newbie, so no doubt I’m not understanding something about how it works. Any help would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:04:19+00:00Added an answer on June 16, 2026 at 8:04 pm

    You are passing the value at allData[i]['cleanFDF'] by reference (decent explanation at https://stackoverflow.com/a/430958/337678). Any changes made to it will be made to the object it refers to, which is still the same object as the original, just assigned to a different variable.

    Making a deep copy of the data will likely fix your issue (Python has a deepcopy library that should do the trick ;)).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following nested dictionaries: Dictionary<int, Dictionary<string, object>> x; Dictionary<int, SortedDictionary<long, Dictionary<string, object>>>
I have an object that consists primarily of a very large nested dictionary: class
I have a array with nested dictionary data like this: [{ link : [
I have a nested dictionary Map<'a,Map<'b,'T>> , so that for a combination of a*b
Suppose I have a dictionary, and it's nested with dictionaries inside. I want to
I have a number of tables, which have nested tables. I using jQuery to
I have some deeply randomly nested dictionary as follows. {'CompilationStatistics': {'CodeGeneration': {'EndTime': '2010-04-21T14:03:11', 'StartTime':
I have a nested dictionary of type following {id_1 : [ {id_2:score},{id_3:score_2} .... and
Suppose I have a nested dictionary 'user_dict' with structure: Level 1: UserId (Long Integer)
I have a nested dictionary along the lines of: {'apple': {'a': 1, 'b': 4,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.