[Tutor] Using Python for accurate calculations
Hello I am working on a function which is going to calculate correlation between two given sets of numbers. Example: x=[10.0, 10.8, 11.3, 10.0, 10.1, 11.1, 11.3, 10.2, 13.5, 12.3, 14.5, 11.0, 12.0, 11.8, 13.4, 11.4, 12.0, 15.6, 13.0, 12.1] y=[0.70, 0.73, 0.75, 0.70, 0.65, 0.65, 0.70, 0.61, 0.70, 0.63, 0.70, 0.65, 0.72, 0.69, 0.78, 0.70, 0.60, 0.85, 0.80, 0.75] However Python stores these numbers like this: x [10.0, 10.801, 11.301, 10.0, 10.1, 11.1, 11.301, 10.199, 13.5, 12.301, 14.5, 11.0, 12.0, 11.801, 13.4, 11.4, 12.0, 15.6, 13.0, 12.1] y [0.69996, 0.72998, 0.75, 0.69996, 0.65002, 0.65002, 0.69996, 0.60999, 0.69996, 0.63, 0.69996, 0.65002, 0.71997, 0.68995, 0.78003, 0.69996, 0.59998, 0.84998, 0.80004, 0.75] The extra digits added by Python are adding error probability to my calculations. Is there a way to overcome this? Thank You :-) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 50, Issue 9
Hello :-) Can someone please explain to me ho can I find out how many elements are there in one record of a list? The problem is as follows: I have a txt file from which I read data into Python. The file looks something like this: 01 bla bla bla 23,15 2345,67 02 alb alb 2,4 890,1 03 bal bla alb lab 567,12345 87,45 I need to be able to discriminate the string parts from the numeric ones. Since the number of words in the file can vary, I have to be able to find out when they are finished and when the floats come in mystring[0]- always integer mystring[1]- string (word) mystring[1-X]- last string (word) mystring[X+1]- always float mystring[X+2]- always float it would have been nice if I could find out the total number of the fields in one list record so that I could then adress them via a variable. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Table like array in Python
Hello :-) I am reading Ivan van Leiningem Learn Python in 24 hours and I am having problems understanding the way arrays work in Python. I used to know Pascal and arrays there were tablelike. Example (cost of something in different countries by different years) Record1 US 2006 22.10 Record2 US 2007 23.45 Record3 UK 2007 22.90 .. RecordN So I could read the record, see if the name of the country in the first cell was what I was looking for and either continue working with the record or resume searching. However in Python, if I understand correctly this example would look like this: US 2006 22.10 US 2007 23.45 UK 2007 22.90 This means that I have to keep a lot of unnesessary information in RAM, not to mention that I would have to scan through the whole array instead of scanning just the required cell. Could anyone please direct me to a good description of working with arrays in Python? And I have problems understanding what dictionaries are for :-( Thank You! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor