I'm a Python beginner who is starting to get familiar with the pymc library. In my program I'm generating random numbers between 1 and 100. When I'm generating random variables, it obviously returns an array with integers (in this case a 10 int array):
customer_names = customer_names.random(size=10)
The history of this post is that I want to relate each int variable to a specific name through a table, as if each name had an identifier, but I don't know how to implement it in the code.
What I want is that when I print(customer_names)
instead of getting an array [ 54 2 45 75 22 19 16 34 67 88]
I want to get [ Jose Maria Carmen Alejandro Davinia Eduardo Carlos Fátima Marc Mireia]
.
I have tried the following:
def identificar_nombres(nc = customer_names):
for i in range (0, 9): #in this case 9 because I'm generating 10 random numbers
if nc[i] == '1':
return 'ANTONIO'
elif nc[i] == '2':
return 'MARIA CARMEN'
else: return nc[i] # process repeatedly with all names in the name dataset
nombres = identificar_nombres(customer_names)
but without result.
Thanks!
Use a dictionary(key-value pair) to store the variables like this:
variables = {1: 'ANTONIO', 2: 'MARIA CARMEN'}
And access it like this:
customer_names = list(variables.values()))
print(customer_names)
Output:
['ANTONIO', 'MARIA CARMEN']