0

I have a set of python classes and each of the classes have some distinct numpy arrays. I want to have a dictionary in each class that has reference to all of arrays in that class. I need this to be able allow an external function to update the values of each array in the objects of these classes.

I figured out that storing the numpy array directly does not work. When the array is updated a new array is created and the dictionary still has the old one.

Is there a way to store a reference to a variable in a dictionary?

  • No, there isn't, python doesn't really support variable references. Can't you just mutate the array instead of assigning a new one to the variable? Well, you could wrap your array in some object, even just a list, e.g. `x = [my_array]`, and the always do something like `x[0] = array_processing(x[0])` – juanpa.arrivillaga Nov 29 '17 at 20:20
  • So read this: https://stackoverflow.com/questions/11222440/python-variable-reference-assignment – juanpa.arrivillaga Nov 29 '17 at 20:24

0 Answers0