Re: Truncation error
May I request you to let me know the steps python follows in order to compute covariance matrix using the inbuilt syntax. np.cov(cov_mat) . >>cov_mat = np.stack((x, y), axis = 0) >>np.cov(cov_mat) On Sun, Oct 11, 2020 at 9:14 AM Grant Edwards wrote: > On 2020-10-10, Peter J. Holzer wrote: > > On 2020-10-07 07:53:55 +0200, Marco Sulla wrote: > >> If you want to avoid float problems, you can use Decimal: > > > > Decimal doesn't avoid floating point problems, because it is a floating > > point format. For example: > > [...] > > > >>> from decimal import * > > >>> a = Decimal(3) > > >>> a > > Decimal('3') > > >>> b = Decimal(1E50) > > >>> b > > Decimal('17629769841091887003294964970946560') > > [...] > > There are two problems with your code: > > 1. You meant Decimal('1e50'). What you typed creates a Decimal value > from the IEEE 64-bit floating point value closest to 1e50. > > 2. You need to increase the context precision. It defaults to 28, > and you're example needs it to be at least 51: > > >>> getcontext().prec = 100 > >>> a = Decimal(3) > >>> b = Decimal('1e50') > >>> c = Decimal(2) > >>> a + b - c - b > Decimal('1') > >>> b - b + a - c > Decimal('1') > >>> a + (b - b) - c > Decimal('1') > >>> a + b - b - c > Decimal('1') > > Like other floating point systems, you still need to know what you're > doing if you want to get the "right" results. > > -- > Grant > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Python's carbon guilt
On 10/10/20 9:58 AM, Peter Pearson wrote: > Python advocates might want to organize their thoughts on > this subject before their bosses spring the suggestion: > > From > https://www.sciencemag.org/news/2020/10/we-re-part-problem-astronomers-confront-their-role-and-vulnerability-climate-change > : > > . . . Astronomers should also abandon popular programming languages > such as Python in favor of efficient compiled languages. Languages > such as Fortran and C++, Zwart calculates, are more than 100 times > more carbon efficient than Python because they require fewer > operations. Most of the math heavy lifting is done by compiled code that is merely called from Python. I seriously doubt there is anything to save by abandoning Python for something that is harder to use, slower, and probably burns way more electricity with all those compile cycles that they'd be forced to do. -- https://mail.python.org/mailman/listinfo/python-list
RE: Problem saving datetime to file and reading it back for a calculation
Thanks for the response. I must have spent hours looking on-line for a method to treat datetime variables yet not one site mentioned the "pickle" module you indicatged. I did, however solve my problem. It may be a kluge but it seems to work. I learned that I cannot use print() to display the value of datetime but once I saved it to a file, I could see it. If I used "d3 = d2.isoformat" it could be sent to a file with a write statement. Apparently, it gives a write/read format and places a T between the date and time as a separator. In trying to read it back into the program and work the calculation, I had to replace the T with a space and some formatting. It all worked. #=== LBD = "LBD" d2 = datetime.now() d2i = d2.isoformat() with open("TimeDate.txt", 'r') as infile: for BottleInfo in infile: # loop to find each line in the file for that dose BottleInfo = BottleInfo.strip() if ((BottleInfo[0:3]== "LBD")): BottleData = BottleInfo[0:43].strip() BottleDataA = BottleData[4:14].strip() BottleDataB = BottleData[16:30].strip() BottleDataC = BottleDataA + " " + BottleDataB print("BottleDataC = <" + BottleDataC + ">") # I guess I could have searched for the "T" and replaced it. print() d1 = BottleDataC import datetime dto = datetime.datetime.strptime(d1, '%Y-%m-%d %H:%M:%S.%f') dti = dto.isoformat() HoursDiff = int((d2-dto).total_seconds()/3600) print("HoursDiff = " + str(HoursDiff)) print() TimeDateInfo=open("TimeDate.txt", "a") TimeDateInfo.write("{0:>5} {1:>25} {2:>5}\n".format (LBD, d2i, HoursDiff)) TimeDateInfo.close() # === Granted, there may be other ways to do this but I actually enjoy the exploration... Still, I would like to see other methods. Steve -Original Message- From: Dieter Maurer Sent: Sunday, October 11, 2020 12:48 PM To: Steve Subject: Re: Problem saving datetime to file and reading it back for a calculation Steve wrote at 2020-10-10 18:17 -0400: >I would like to use the line: >HoursDiff = int((d2-d1).total_seconds()/3600) to determine the >difference in hours between two timedate entries. > >The variable d2 is from datetime.now() >and d1 is read from a text file. > >I can save d2 to the file only if I convert it to string and, at a later >date, it gets read back in as d1 as string. The variable d1 as string will >not work in the HoursDiff statement. Python's "pickle" module provides support for storing (most) objects to files and read them back. -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem saving datetime to file and reading it back for a calculation
On 2020-10-11 20:25, Steve wrote: Thanks for the response. I must have spent hours looking on-line for a method to treat datetime variables yet not one site mentioned the "pickle" module you indicatged. I did, however solve my problem. It may be a kluge but it seems to work. I learned that I cannot use print() to display the value of datetime but once I saved it to a file, I could see it. If I used "d3 = d2.isoformat" it could be sent to a file with a write statement. Apparently, it gives a write/read format and places a T between the date and time as a separator. In trying to read it back into the program and work the calculation, I had to replace the T with a space and some formatting. It all worked. [snip] Given: import datetime To convert a datetime d to an ISO-format string, you can use: s = d.isoformat() To convert an ISO-format string s to a datetime, you can use: d = datetime.datetime.fromisoformat() -- https://mail.python.org/mailman/listinfo/python-list
RE: Problem saving datetime to file and reading it back for a calculation
Thanks for the responses. Somehow, all of my python messages were shifted into the deleted folder so I missed all of them until I caught the one from MRAB. I will sift through them and probably update my technique to use seconds as suggested. Still, I enjoyed the kluge I created making it work based on discovery... Footnote: If 666 is evil then 25.8 is the square root of all evil. -- https://mail.python.org/mailman/listinfo/python-list
numpy covariance (was Re: Truncation error)
On 10/11/2020 8:17 AM, Meghna Karkera wrote: May I request you to let me know the steps python follows in order to compute covariance matrix using the inbuilt syntax. > np.cov(cov_mat) 1. When starting a new topic, start a new thread with a new topic. 2. Questions about the internals of a 3rd party module are better asked on the discussion forum for that module. Such exist for numpy. 3. Your question is too vague to reliably answer. I am not sure what you mean by 'inbuilt syntax'. I presume that numpy cov calls 1 or more functions from the included LinPack code. If this is not enough of an answer, read the numpy doc and code and if you still have questions, ask a more detailed question on a numpy forum. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
FW: NEED SOLUTION FOR ERROR
Sent from Mail for Windows 10 From: hey Sent: Saturday, October 10, 2020 7:40 PM To: python-list@python.org Subject: NEED SOLUTION FOR ERROR I am Akshat Sharma one of python user from INDIA . I am facing problem in getting pip installed. When I am trying to install a module using PIP it showing me error : No such file found in directory . Then I tried to install pip doing so , I am getting another error : OSError [errno 9] Bad File Descriptor. Please guide me what should I do to overcome this type of error. THANK YOU Regards Sent from Mail for Windows 10 -- https://mail.python.org/mailman/listinfo/python-list
Re: FW: NEED SOLUTION FOR ERROR
On 2020-10-11 09:13, hey wrote: Sent from Mail for Windows 10 From: hey Sent: Saturday, October 10, 2020 7:40 PM To: python-list@python.org Subject: NEED SOLUTION FOR ERROR I am Akshat Sharma one of python user from INDIA . I am facing problem in getting pip installed. When I am trying to install a module using PIP it showing me error : No such file found in directory . Then I tried to install pip doing so , I am getting another error : OSError [errno 9] Bad File Descriptor. Please guide me what should I do to overcome this type of error. THANK YOU Regards You could try using the pip module via the Python launcher. Instead of: pip install something try: py -m pip install something -- https://mail.python.org/mailman/listinfo/python-list
Fwd: Truncation error
May I request you to let me know the steps python follows in order to compute covariance matrix using the inbuilt syntax. np.cov(cov_mat) . >>cov_mat = np.stack((x, y), axis = 0) >>np.cov(cov_mat) On Sun, Oct 11, 2020 at 9:14 AM Grant Edwards wrote: > On 2020-10-10, Peter J. Holzer wrote: > > On 2020-10-07 07:53:55 +0200, Marco Sulla wrote: > >> If you want to avoid float problems, you can use Decimal: > > > > Decimal doesn't avoid floating point problems, because it is a floating > > point format. For example: > > [...] > > > >>> from decimal import * > > >>> a = Decimal(3) > > >>> a > > Decimal('3') > > >>> b = Decimal(1E50) > > >>> b > > Decimal('17629769841091887003294964970946560') > > [...] > > There are two problems with your code: > > 1. You meant Decimal('1e50'). What you typed creates a Decimal value > from the IEEE 64-bit floating point value closest to 1e50. > > 2. You need to increase the context precision. It defaults to 28, > and you're example needs it to be at least 51: > > >>> getcontext().prec = 100 > >>> a = Decimal(3) > >>> b = Decimal('1e50') > >>> c = Decimal(2) > >>> a + b - c - b > Decimal('1') > >>> b - b + a - c > Decimal('1') > >>> a + (b - b) - c > Decimal('1') > >>> a + b - b - c > Decimal('1') > > Like other floating point systems, you still need to know what you're > doing if you want to get the "right" results. > > -- > Grant > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem saving datetime to file and reading it back for a calculation
On 11Oct2020 20:39, Steve wrote: >Still, I enjoyed the kluge I created making it work based on discovery... Poking around in the datetime module will definitely make you aware of its power, and its pitfalls. Well worth doing. At the very least you'll usually want it when printing times out for humans. But seconds is generally simpler and reliable, particularly as it tosses timezones straight out the window - it is all just arithmetic. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list