944,092 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 2567
  • Python RSS
Sep 28th, 2005
0

Problem with Deviation function

Expand Post »
Hello,

I'm very new to python script and I am attempting to understand a part of a program developed at my work place because the have the most computer knowledge here, though still very little and the person who developed the program is no longer accesible. Here's the problem i'm attempting to solve:

I have a .txt file that I believe is converted to an array by a comma delinated string. there is then a tab delinated string of the first four terms as floats. the program is supposed to compare the values in the array to desired values given by the program and find a value closest to the desired value given in the array based on a user inputed allowed percentage deviation. The program is working properly, however, rather than pulling the closest value to the given desired value from the array it is pulling something else that I am assuming is one of three things.

a. it's pulling the first value that it finds in the interval
b. it's pulling all the values in the interval and then averaging the value
c. it's pulling the first in the interval, the last, and finding the midpoint

what i would like it to do is either find the the exact integer in the deviation that is closest to the given, or pull the highest value in the range, either would work, it's just whichever is easiest.

so here's what the code looks like: (I think this is where the program is sorting this list)

i could not find the value for "ideal" anywhere in the program, and perhaps that is the very problem.

D=[abs(ref[i]-read[0][2]),abs(ref[i]-read[1][2]),abs(ref[i]-read[2][2])]
ref[i] is the matrix of ideal values chosen by the user
read=[split_s(current.readline()),split_s(current.readline()),split_s(current.readline())]
dev=the allowed deviation percentage entered in float form by user.
Python Syntax (Toggle Plain Text)
  1. def sort(ideal,D,dev):
  2. if D[0] > D[1]:
  3. if D[1] > D[2]:
  4. if D[2] < ideal*dev:
  5. return 2
  6. else:
  7. return -1
  8. else:
  9. if D[1] < ideal*dev:
  10. return 1
  11. else:
  12. return -1
  13. else:
  14. if D[0] < D[2]:
  15. if D[0] < ideal*dev:
  16. return 0
  17. else:
  18. return -1
  19. else:
  20. if D[2] < ideal*dev:
  21. return 2
  22. else:
  23. return -1
I greatly appreciate any help that could be provided!
Thank you,
Michael Morris

Edit: code tags added by vegaseat 09/30/05
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mikul86 is offline Offline
2 posts
since Sep 2005
Sep 28th, 2005
0

Re: Problem with Deviation function

ok, so I tried assigning a value "ideal=ref[i]", but that didn't fix the problem, though I suppose that it could have been one of the problems anyways. I did a little test I i think i've narrowed down the problem to the program only looking for values close to the ideal value that exceed the ideal value, but not potential values that preceed the ideal.

in short, the program looks for the ideal and if it can't find it then it looks for the next best value past it. this is bad because sometimes the best value is actually the before the ideal.

does that help my case at all? ^_^
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mikul86 is offline Offline
2 posts
since Sep 2005
Sep 28th, 2005
0

Re: Problem with Deviation function

Please put your Python code between code tags
[ code]your code here[/code]

Removed the space between [ and c for this to work!

Python needs the proper indentation and with the amount of if and else groupings you have, it is almost impossible to figure out what belongs to what!
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: duplicate entry through web form into oracle
Next Thread in Python Forum Timeline: File Handling with Python





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC