I am pulling values from a text file that has two columns. The text file looks exactly as shown below, where the first number in every row is the "time" value, and the second number is just a "number"
0,311.235
1,0
2,5316.36
3,-4086.90
4,-1739.985
I got the code figured out for the main part except for one thing. I still to check for equivalence of positives and negatives. Read below and follow the code:
workspace = 'C:\\Users\master\Desktop'
time= np.loadtxt(workspace +'\\project.txt', delimiter = ',', usecols = range(1))
num = np.loadtxt(workspace +'\\project.txt', delimiter = ',', usecols = range(1,2))
last_neg_num = 0
for i in range(len(num)-1, -1, -1):
if num[i] < 0:
num[i] += 2*last_neg_num
last_neg_num = num[i]
last_pos_num = 0
for i in range(len(num)-1, -1, -1):
if num[i] > 0:
num[i] += 2*last_pos_num
last_pos_num = num[i]
print num[0], num[1]
This is just an example text file. I could have many more or less time values and many more numbers associated with it, and they could be either negative or positive.
Now, here is I want to do with the content in the text file:
- Bring all the negative values and positive values at time=0.
- To complete step 1, I need to take the very last value of either positive or negative number, and move it on the left after multiplying with the constant of 2.
For ex: -1739.985 is at time=4, so I need to move that time=3, and when I move that to time=3, I multiply it with 2, giving me -3479.97. The value of -4086.90 is sitting at time=3 as well, thus I will need to add -3479.97+(-4086.90) = -7566.87. Now, we have one number at time=3. However, there are no more numbers on the negative side. But, it needs to go to time=0. For that I need to go through time=2 and time=1. To go from time=3 to time=2, I need to again multiply -7566.87 by 2 = -15133.74. Since, there is nothing to add at time=2 (adding 0), I need to move to time=1 by multiplying -15133.74*2 = -30267.48, and finally to time=0 giving me -60534.96.
Doing the same thing with the positives, I got 21576.675, which clearly in terms of magnitude is not equal to the final negative value at time=0. Thus, the code needs to tell that they are not equivalent.
My code doesn't multiply the answer by 2, if at any time=, there is no number either in negative or positive side. How to solve that? Now, obviously the positives are not equal as negatives for this particular problem. The values needed to be considered equal if one of the values is greater by 1 but smaller than or equal to 15. So, for ex: at time=0, if I have 350 positive, and 359 at negative, then they are equal because negative is +9 from positive.
I hope that make sense. I also need a visual that shows what is in the text file. Bar graph should do.