0

What I want to do is trying to get different values of p_y_given_x for different sigma2_n separately in each line? When I use append it gives me result in one array. But I want separate results for each 0.2 for p_y_given_x.

Is there any hint for me?

for sigma2_n in np.arange(0.2,0.9):

    p_y_given_x= np.exp(-(y_new-alphabet[t])**2/2/sigma2_N)

the result should be like this

p_y_given_x=[2 1 5 6 7
             5 7 8 9 0]

p_y_given_x2=[3 5 8 7
             5 4 7 0]

p_y_given_x3=[1 4 9 6
             5 3 4 5]

...... for each value of sigma2_N, it gets value for p_y_given_x, but I want to get this new value in the different name, for example:

p_y_given_x1
p_y_given_x2
p_y_given_x3 and so on
is there any solution for it with a for loop?

If I use append() function it attaches all the results in one array and I don't want this, the result will be

i=[]     
for sigma2_n in np.arange(0.2,0.9):
    p_y_given_x= np.exp(-(y_new-alphabet[t])**2/2/sigma2_N)
    i.append(sigma2_N)

[p_y_given_x1,p_y_given_x2,p_y_given_x3,....]
Luc Blassel
  • 394
  • 4
  • 15
Pouyi
  • 7
  • 7

1 Answers1

2

You can store the different lists in a dict and identify each list using a key like below:

d = {}
i = 0
for sigma2_n in np.arange(0.2,0.9):
    d['p_y_given_x'+str(i)] = np.exp(-(y_new-alphabet[t])**2/2/sigma2_N)
    i += 1
Jay
  • 24,173
  • 25
  • 93
  • 141