0

Hi I am creating a loop function in which I have numpy variable stored first with some values. Post some checks and getting the value in by pasting etc, I get the value in string for which I want to fetch the numpy array values. I think the code snippet below will make it clear.

#Original array in loop above the string name
values=np.array([1,2,3]) 

# create string name after comparing on various factors
string=str("values")

#now I want is that when I print string, the values should come of the array and not the text string
print(string)

I hope I am clear of the task in hand and my question is clear to the audience.

Thanks

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Sahil Jain
  • 48
  • 7
  • 1
    https://stackoverflow.com/questions/1373164/how-do-i-create-variable-variables. Probably you should just use a dict instead of endless variables. i.e. `d = {'values': np.array([1,2,3])}`. Then you can do `mystr = 'values'; d[mystr]` to get the array you want. – ALollz Mar 02 '21 at 15:27
  • Hi, yes..it did work but it proved to be a long process if the length of dictionary keep on increasing. At present I had six variables so I created a dictionary to solve the issue this time. Thanks :) – Sahil Jain Mar 02 '21 at 15:52

0 Answers0