-2

I have done a ton of preprocessing and math on this data to arrive at two equally sized 3xN numpy arrays. A and B.

A = integers that have been classified as labels to predict B. B = time series data.

I also have C which is just B[1:]

A and B are equal at their respective time steps and I can't figure out a better way to make a list of the next time step of B, so I have A[0:-1], B[0:-1] and C[1:])

I know that A + or - B is always == to at least 1 integer in C.

Example:

if A = [2,3,4] and B = [5,2,1] I know that at least 1 of C will be a 7,8,1,3, or any other combination of those numbers + or - each other.

How can I make a simple function to do this operation and check if it IS == to C and then store it as a key in a dictionary? The goal would be to create a neural network once this is complete to evaluate new data.

  • Can you achieve by an intersection? Can you show the desired outcomes? – iGian Nov 18 '18 at 16:33
  • Had no idea this was even a thing. I'm only a year into Python but this is very helpful and a great push into the right direction, I'll play around with it. Thank you. Specifically though, if you were to do this with an intersection, what do you think the best approach would be? – Jeffrey Ely Nov 18 '18 at 16:36
  • Let's say I have a label for every possible combination of the 3 numbers, A[0] + B[0], A[1] + B[0], A[0] - B[0] and so on... And I want to do that operation, check if the result of every combination is in fact one of the 3 integers in C, and if so, store that in a dictionary with the label name. Since it's + or - each integer, say the labels are dAB for A - B and dBA for B - A and so on. Label names don't matter as they are variables, but the specific operation is a little confusing to me. Is there an easy way to do this in Python with that intersection function? – Jeffrey Ely Nov 18 '18 at 16:41
  • For the combination check this: https://stackoverflow.com/questions/12935194/combinations-between-two-lists --- For the intersection check this: https://stackoverflow.com/questions/3697432/how-to-find-list-intersection/33067553 – iGian Nov 18 '18 at 16:52
  • 1
    This will lead me to do exactly what I want, thank you very much! – Jeffrey Ely Nov 18 '18 at 17:00

1 Answers1

0

Just to give an example, if I understand what you are looking for:

a = [2,3,4]
b = [5,2,1]
c = set(b[1:])

sums = set([ aa + bb for aa in a for bb in b ])
subs1 = [ (aa - bb) for aa in a for bb in b if (aa - bb) > 0]
subs2 = [ bb - aa for bb in b for aa in a if (bb - aa) > 0]
subs = set(subs1 + subs2)

print(sums)
print(subs)
print(c)

print(len(sums & c)) #=> 0 c does not contains any of sums
print(len(subs & c)) #=> 2 c contains two of subs
iGian
  • 11,023
  • 3
  • 21
  • 36
  • Wow thank you so much. The only thing I'm missing is that I need A + or - B and then check for an intersection in C, store that as a dictionary with the label A+B or A-B or B-A or what ever. Just for example since a = [2,3,4] and b = [5,2,1] I need it to look for 2 + 5 or 2-5 and check if 3 or 7 is in C. But man this sure is extremely helpful. You rock! – Jeffrey Ely Nov 18 '18 at 17:12
  • 1
    Edit: *doh!* It took me a minute to actually read and understand the code. You sir are a gentleman and a scholar. I'm still learning Python and just realize that's exactly what this code does. :-) A million thank yous. – Jeffrey Ely Nov 18 '18 at 17:23