I have two numpyarrays named dec_pair and dec_community in a module named config.py, initialized to zero:
dec_pair = numpy.zeros(200)
dec_community = numpy.zeros(200)
Now, I am trying to access them from some other module, say roc.py, where their names are being formed based on a input variable, i.e.
import config
def dosomething(name):
local_name = 'config.py'+name
eval(local_name)[i:] += 1
where name can be pair or community. The issue is, eval(local_name) is returning the length of the numpy array i.e. 200 here and not the array itself, which gives me this error:
ValueError: cannot slice a 0-d array
However, when I do the same thing on the python interpreter, it runs smoothly :
>>> dec_pair = numpy.zeros(5)
>>> name = 'pair'
>>> local_name = 'dec_'+name
>>> eval(local_name)
array([ 0., 0., 0., 0., 0.])
Any idea as to what I am doing wrong and what would be the correct way to do it ?
configand it has variables likeconfig.pydec_pair? 2) this code design seems fishy and eval us unsafe. 3) did you mean to initialize the arrays likenumpy.zeros(200)instead ofnumpy.array(200)?nump.zeros(200), made a mistake while typing ..I want to access it and modify it from the moduleroc.pyconfig.pydec_pair? Or what? What's the point of thedosomethingfunction?dec_pairanddec_communityfrom the moduleroc.py, which receives the name of the array to be modified on as an input. Therefore, I am trying to access the correct array based on the parametername. Maybe I did this horribly wrong .. what is the correct method to achieve it ?