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,....]
3
  • 1
    Why don't you want a list? Why is p_y_given_x1 preferred to p_y_given_x[0]? Commented Feb 1, 2019 at 10:19
  • You could use a dict. Commented Feb 1, 2019 at 10:19
  • yes for me doesn't matter, in my task, I should compare these results with each other and make a conclusion that's why I need them separately, how can i do it with dict? Commented Feb 1, 2019 at 10:22

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.