-4
Opa my beasts, I am with a difficulty, I made a combination list of 0 and 1, where 1 will be replaced by positive values of a list, and 0 will be replaced by negative values of another list and added with another list of numbers. (all lists have 25 values/columns)
I’ve been able to replace the positive values for when I have 1, but not the negative values for 0, I’ve tried a lot and this below was my last and still nothing. If you can help me I’d be very grateful, hugs.
combina = product([0, 1], repeat=25)
for item in combina:
res = sum([v + i*p + (not i)*n for i,v,p,n in zip(item, inicial, positivos, negativos)])
print(res)
DETAILED UPDATE
Leaving the script unmounted at the part I’m having problems:
positivos = [0.0195, 0.0194, 0.0193, 0.0193, 0.0196, 0.0205, 0.0204, 0.0212, 0.0202, 0.0189, 0.0190, 0.0200, 0.0188, 0.0195, 0.0199, 0.0209, 0.0199, 0.0199, 0.0197, 0.019, 0.0201, 0.0197, 0.0196, 0.0189, 0.0194]
negativos = [-0.0298, -0.0298, -0.0300, -0.0300, -0.0297, -0.0288, -0.0289, -0.0281, -0.0291, -0.0304, -0.0303, -0.0293, -0.0305, -0.0298, -0.0294, -0.0283, -0.0294, -0.0294, -0.0296, -0.0302, -0.0292, -0.0296, -0.0297, -0.0304, -0.0298]
combina = product([0, 1], repeat=25)
for item in combina:
for i,p,n in zip(item, positivos, negativos):
teste = i*p
print(teste)
Printing what only the combination will show: (I will put only one part)
0
1 # os valores que são 1, eu já consigo substituir pelo da lista positivos
0
0
0
0
0
In list order, note that the positive number you show is the second value of the positive list, because the first is 0 (which would have to be the first negative)
And I’d have to leave like this:
-0.0298
0.0194
-0.0300
-0.0300
-0.0297
-0.0288
-0.0289
But logically it would have to be based on that first code that I showed, where everything is on one line.
Junior, I’m not sure what your goal is. You can edit your post in more detail about this problem you’re trying to solve?
– Allan Juan
@Allanjuan In which part did not understand friend?
– Junior Lopes
I’m not sure what it is you’re trying to do. If you give an input/output example demonstrating what the program should do, I think it may be clearer
– Allan Juan
@Allanjuan updated
– Junior Lopes
I drafted an answer and, after I saw its details, decided to delete it. Something else. even with the details you added I still don’t understand the focus of the issue.
– Solkarped
@Solkarped the focus is that the 0 is not coming out with the negative values, in the last two examples, compare them, of to understand well.
– Junior Lopes
Junior, every numeric set has value
NULOfor the addition operation. If you are working with integers the valueNULOwill be0. If you are working with real numbers the valueNULOwill be0.0. Note that0is a valueNULO, that is to say,0nor ispositivoand neithernegativo.– Solkarped
@Solkarped understood in what you still had doubts, I updated the penultimate example, a check, where the value is 0.0194, is pq printing only the "i", in place of it would be 1
– Junior Lopes
Junior, the value "0" HAS NO SIGN, neither positive nor negative. ``0
é um valorNULL`.– Solkarped
@Solkarped, I know, but where zero is I want to replace with a negative value, the list of 0 and 1 that comes out, is just for combination reference
– Junior Lopes
Then you should create a constraint so that when the value is
<= 0the result is0and, if not (value> 0) the result is1.– Solkarped
Why you have to logically solve this problem in a row?
– Lucas Maraal
@Lucasmaraal because I have other functions below, which can influence the result, if this line is divided into several "for" and "if", but if you have any suggestion tell me that I try without problems, will not influence
– Junior Lopes
I would first create two lists
pandn, one with the positives and the other with the negatives and then concatenate thep + n. Finally, I would sum up the elements of this new list created with the other list you quote.– Lucas Maraal
@Lucasmaraal good I’ll try, put as response in the post and with the script, so moves the topic and is easier to see.
– Junior Lopes