Convert a scientific notation to decimal number, and still keeping the data format as float64
Here is my question: I am using the numpy.std formula to calculate the standart deviation. However, the result comes as a number in scientific notation. Therefore I am asking, How to convert a scientific notation to decimal number, and still keep the data format as float64 ? Or is there any workaround to get the initial standart deviation result as a decimal number? Here is my code: stdev=numpy.std(dataset) print(stdev) Result: 4.449e-05 print(stdev.dtype) Result: float64 Solutions such as this: stdev=format(stdev, '.10f') converts the data into a string object! which I don't want. Expected result: I am willing to have a result as a decimal number in a float64 format. System: (Python 3.7.4 running on Win10) Regards, -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert a scientific notation to decimal number, and still keeping the data format as float64
On 10/18/19 4:35 AM, doganad...@gmail.com wrote: > Here is my question: > > > I am using the numpy.std formula to calculate the standart deviation. > However, the result comes as a number in scientific notation. > Therefore I am asking, How to convert a scientific notation to decimal > number, and still keep the data format as float64 ? > > Or is there any workaround to get the initial standart deviation result as a > decimal number? > > > Here is my code: > > stdev=numpy.std(dataset) > print(stdev) > Result: 4.449e-05 > > > print(stdev.dtype) > Result: float64 > > > Solutions such as this: > > stdev=format(stdev, '.10f') > converts the data into a string object! which I don't want. > > > Expected result: I am willing to have a result as a decimal number in a > float64 format. > > System: (Python 3.7.4 running on Win10) > > > Regards, The number itself isn't in scientific notation or a fixed point number, but is a floating point number that is expressed internally as an integer times a power of 2 (that is the basic representation format for floating point). Scientific notation vs fixed point notation is purely an OUTPUT configuration, not a function on how the number is stored (so in one sense IS more closely linked to a string than the float itself). -- Richard Damon -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert a scientific notation to decimal number, and still keeping the data format as float64
On 10/18/19 10:35 AM, doganad...@gmail.com wrote: Here is my question: I am using the numpy.std formula to calculate the standart deviation. However, the result comes as a number in scientific notation. Therefore I am asking, How to convert a scientific notation to decimal number, and still keep the data format as float64 ? Or is there any workaround to get the initial standart deviation result as a decimal number? Here is my code: stdev=numpy.std(dataset) print(stdev) Result: 4.449e-05 print(stdev.dtype) Result: float64 Solutions such as this: stdev=format(stdev, '.10f') converts the data into a string object! which I don't want. Expected result: I am willing to have a result as a decimal number in a float64 format. System: (Python 3.7.4 running on Win10) Regards, Hi, doganad...@gmail.com why don't you use print("{0:10.5f}".format(x)) The only thing you want is a specific form of the human readable representation of the number. For this it is not necessary the convert the *number* itself definitely to a string. You only have to make a temp copy of x for printing purposes. Linux Mint Tara in Spyder(Python 3.6) : x=4.449e-05 print(x) 4.449e-05 print("{0:8.5f}".format(x)) 0.5 print(x) 4.449e-05 hth Gys -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert a scientific notation to decimal number, and still keeping the data format as float64
On Friday, October 18, 2019 at 2:46:42 PM UTC+3, Gys wrote: > On 10/18/19 10:35 AM, doganad...@gmail.com wrote: > > > > Here is my question: > > > > > > I am using the numpy.std formula to calculate the standart deviation. > > However, the result comes as a number in scientific notation. > > Therefore I am asking, How to convert a scientific notation to decimal > > number, and still keep the data format as float64 ? > > > > Or is there any workaround to get the initial standart deviation result as > > a decimal number? > > > > > > Here is my code: > > > > stdev=numpy.std(dataset) > > print(stdev) > > Result: 4.449e-05 > > > > > > print(stdev.dtype) > > Result: float64 > > > > > > Solutions such as this: > > > > stdev=format(stdev, '.10f') > > converts the data into a string object! which I don't want. > > > > > > Expected result: I am willing to have a result as a decimal number in a > > float64 format. > > > > System: (Python 3.7.4 running on Win10) > > > > > > Regards, > > > > Hi, doganad...@gmail.com > > why don't you use > > print("{0:10.5f}".format(x)) > > The only thing you want is a specific form of the human readable > representation of the number. For this it is not necessary the convert > the *number* itself definitely to a string. You only have to make a > temp copy of x for printing purposes. > > Linux Mint Tara in Spyder(Python 3.6) : > > x=4.449e-05 > > print(x) > 4.449e-05 > > print("{0:8.5f}".format(x)) > 0.5 > > print(x) > 4.449e-05 > > hth > Gys Hello, I don't only need a human readable representation of number, I need to use it further, do things such as putting it in a pandas object and saving it to an excel file. Doing things such as x="{0:10.5f}".format(x) gives a str object as a result: -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert a scientific notation to decimal number, and still keeping the data format as float64
On Friday, October 18, 2019 at 2:21:34 PM UTC+3, Richard Damon wrote: > On 10/18/19 4:35 AM, doganad...@gmail.com wrote: > > Here is my question: > > > > > > I am using the numpy.std formula to calculate the standart deviation. > > However, the result comes as a number in scientific notation. > > Therefore I am asking, How to convert a scientific notation to decimal > > number, and still keep the data format as float64 ? > > > > Or is there any workaround to get the initial standart deviation result as > > a decimal number? > > > > > > Here is my code: > > > > stdev=numpy.std(dataset) > > print(stdev) > > Result: 4.449e-05 > > > > > > print(stdev.dtype) > > Result: float64 > > > > > > Solutions such as this: > > > > stdev=format(stdev, '.10f') > > converts the data into a string object! which I don't want. > > > > > > Expected result: I am willing to have a result as a decimal number in a > > float64 format. > > > > System: (Python 3.7.4 running on Win10) > > > > > > Regards, > > The number itself isn't in scientific notation or a fixed point number, > but is a floating point number that is expressed internally as an > integer times a power of 2 (that is the basic representation format for > floating point). > > Scientific notation vs fixed point notation is purely an OUTPUT > configuration, not a function on how the number is stored (so in one > sense IS more closely linked to a string than the float itself). > > -- > Richard Damon Hello Richard, You seem so right. But what will we do with those strings with 'e' in it? There are ways to present those in a 'normal' way with formatting. However, the result of those formatting turns them into str object and which limits you to do any further numerical things with them. Another thing which I have observed, while doing some experimental thing is that: >>> 0.0 0.0 >>> 0.1 0.1 >>> 0.01 0.01 >>> 0.001 0.001 >>> 0.0001 0.0001 >>> 0.1 1e-05 Again another thing with 1e-05! instead of 0.1 , Is there anything I can do about it? -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert a scientific notation to decimal number, and still keeping the data format as float64
On 10/18/19 8:52 AM, doganad...@gmail.com wrote: > On Friday, October 18, 2019 at 2:46:42 PM UTC+3, Gys wrote: >> On 10/18/19 10:35 AM, doganad...@gmail.com wrote: >>> Here is my question: >>> >>> >>> I am using the numpy.std formula to calculate the standart deviation. >>> However, the result comes as a number in scientific notation. >>> Therefore I am asking, How to convert a scientific notation to decimal >>> number, and still keep the data format as float64 ? >>> >>> Or is there any workaround to get the initial standart deviation result as >>> a decimal number? >>> >>> >>> Here is my code: >>> >>> stdev=numpy.std(dataset) >>> print(stdev) >>> Result: 4.449e-05 >>> >>> >>> print(stdev.dtype) >>> Result: float64 >>> >>> >>> Solutions such as this: >>> >>> stdev=format(stdev, '.10f') >>> converts the data into a string object! which I don't want. >>> >>> >>> Expected result: I am willing to have a result as a decimal number in a >>> float64 format. >>> >>> System: (Python 3.7.4 running on Win10) >>> >>> >>> Regards, >>> >> Hi, doganad...@gmail.com >> >> why don't you use >> >> print("{0:10.5f}".format(x)) >> >> The only thing you want is a specific form of the human readable >> representation of the number. For this it is not necessary the convert >> the *number* itself definitely to a string. You only have to make a >> temp copy of x for printing purposes. >> >> Linux Mint Tara in Spyder(Python 3.6) : >> >> x=4.449e-05 >> >> print(x) >> 4.449e-05 >> >> print("{0:8.5f}".format(x)) >> 0.5 >> >> print(x) >> 4.449e-05 >> >> hth >> Gys > Hello, > > I don't only need a human readable representation of number, I need to use it > further, do things such as putting it in a pandas object and saving it to an > excel file. > > Doing things such as > x="{0:10.5f}".format(x) > gives a str object as a result: > If you are going to use it further as a floating point binary number, why do you need to do ANYTHING to it. As I said, the exponential format is just a string representation of the binary value (just like the 0.0005 is). If you put it into something that stores the float64 representation, that doesn't have anything like an exponential vs decimal format. (Depending on how you put it into excel, that may actually use a string representation if something like a CSV file.) -- Richard Damon -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert a scientific notation to decimal number, and still keeping the data format as float64
On 10/18/19 9:03 AM, doganad...@gmail.com wrote: > On Friday, October 18, 2019 at 2:21:34 PM UTC+3, Richard Damon wrote: >> On 10/18/19 4:35 AM, doganad...@gmail.com wrote: >>> Here is my question: >>> >>> >>> I am using the numpy.std formula to calculate the standart deviation. >>> However, the result comes as a number in scientific notation. >>> Therefore I am asking, How to convert a scientific notation to decimal >>> number, and still keep the data format as float64 ? >>> >>> Or is there any workaround to get the initial standart deviation result as >>> a decimal number? >>> >>> >>> Here is my code: >>> >>> stdev=numpy.std(dataset) >>> print(stdev) >>> Result: 4.449e-05 >>> >>> >>> print(stdev.dtype) >>> Result: float64 >>> >>> >>> Solutions such as this: >>> >>> stdev=format(stdev, '.10f') >>> converts the data into a string object! which I don't want. >>> >>> >>> Expected result: I am willing to have a result as a decimal number in a >>> float64 format. >>> >>> System: (Python 3.7.4 running on Win10) >>> >>> >>> Regards, >> The number itself isn't in scientific notation or a fixed point number, >> but is a floating point number that is expressed internally as an >> integer times a power of 2 (that is the basic representation format for >> floating point). >> >> Scientific notation vs fixed point notation is purely an OUTPUT >> configuration, not a function on how the number is stored (so in one >> sense IS more closely linked to a string than the float itself). >> >> -- >> Richard Damon > > Hello Richard, > > You seem so right. But what will we do with those strings with 'e' in it? > > There are ways to present those in a 'normal' way with formatting. However, > the result of those formatting turns them into str object and which limits > you to do any further numerical things with them. > > Another thing which I have observed, while doing some experimental thing is > that: > 0.0 > 0.0 > 0.1 > 0.1 > 0.01 > 0.01 > 0.001 > 0.001 > 0.0001 > 0.0001 > 0.1 > 1e-05 > > Again another thing with 1e-05! instead of 0.1 , Is there anything I can > do about it? The 'e' is only part of the string representation presentation of the value. By default, python decides to present small numbers in exponential format. If you don't like that, when you print the numbers specify the format YOU want, rather than taking the default. Note, that print() by necessity converts an objects value to a string, and this conversion for floats uses exponential notation by default for small numbers. If you don't like it, then use an explicit format for the conversion. An alternative might be to change from using a float64 to making it something like a Decimal. -- Richard Damon -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert a scientific notation to decimal number, and still keeping the data format as float64
On Friday, October 18, 2019 at 4:17:51 PM UTC+3, Richard Damon wrote: > On 10/18/19 9:03 AM, doganad...@gmail.com wrote: > > On Friday, October 18, 2019 at 2:21:34 PM UTC+3, Richard Damon wrote: > >> On 10/18/19 4:35 AM, doganad...@gmail.com wrote: > >>> Here is my question: > >>> > >>> > >>> I am using the numpy.std formula to calculate the standart deviation. > >>> However, the result comes as a number in scientific notation. > >>> Therefore I am asking, How to convert a scientific notation to decimal > >>> number, and still keep the data format as float64 ? > >>> > >>> Or is there any workaround to get the initial standart deviation result > >>> as a decimal number? > >>> > >>> > >>> Here is my code: > >>> > >>> stdev=numpy.std(dataset) > >>> print(stdev) > >>> Result: 4.449e-05 > >>> > >>> > >>> print(stdev.dtype) > >>> Result: float64 > >>> > >>> > >>> Solutions such as this: > >>> > >>> stdev=format(stdev, '.10f') > >>> converts the data into a string object! which I don't want. > >>> > >>> > >>> Expected result: I am willing to have a result as a decimal number in a > >>> float64 format. > >>> > >>> System: (Python 3.7.4 running on Win10) > >>> > >>> > >>> Regards, > >> The number itself isn't in scientific notation or a fixed point number, > >> but is a floating point number that is expressed internally as an > >> integer times a power of 2 (that is the basic representation format for > >> floating point). > >> > >> Scientific notation vs fixed point notation is purely an OUTPUT > >> configuration, not a function on how the number is stored (so in one > >> sense IS more closely linked to a string than the float itself). > >> > >> -- > >> Richard Damon > > > > Hello Richard, > > > > You seem so right. But what will we do with those strings with 'e' in it? > > > > There are ways to present those in a 'normal' way with formatting. However, > > the result of those formatting turns them into str object and which limits > > you to do any further numerical things with them. > > > > Another thing which I have observed, while doing some experimental thing is > > that: > > > 0.0 > > 0.0 > > > 0.1 > > 0.1 > > > 0.01 > > 0.01 > > > 0.001 > > 0.001 > > > 0.0001 > > 0.0001 > > > 0.1 > > 1e-05 > > > > Again another thing with 1e-05! instead of 0.1 , Is there anything I > > can do about it? > > The 'e' is only part of the string representation presentation of the > value. By default, python decides to present small numbers in > exponential format. If you don't like that, when you print the numbers > specify the format YOU want, rather than taking the default. > > Note, that print() by necessity converts an objects value to a string, > and this conversion for floats uses exponential notation by default for > small numbers. If you don't like it, then use an explicit format for the > conversion. > > An alternative might be to change from using a float64 to making it > something like a Decimal. > > -- > Richard Damon By taking the default OUTPUT of a numpy formula, in my case standart deviation, I am using the advantage of saving the result into an excel file without any problems.(they come as numpy.float64) From there, The excel takes all the things as they are and some of my small numbers are shown with the 'e' on the excel sheet. Which I am trying to avoid. I don't need 100 numbers after the comma. What I need is a reasonable amount of decimal numbers to show that the number is small enough, also keeping them in float64, in my case to save them into excel file. One important thing to say is that, if I convert them into string and save them on excel they come with 'dot' instead of comma. And If try to translate the 'dot' manually into 'comma' the excel gives warning message to turn those inputs into numbers. Which I also avoid. If this is Python default, showing all numbers smaller than 0.0001 with 'e' and there is no way to have them in both a human readable and excel savable form. what sould I do? Should I consider using another programming language? If yes, then this language could be callable from within python and I might do things I can. -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert a scientific notation to decimal number, and still keeping the data format as float64
On Sat, Oct 19, 2019 at 12:51 AM wrote: > By taking the default OUTPUT of a numpy formula, in my case standart > deviation, I am using the advantage of saving the result into an excel file > without any problems.(they come as numpy.float64) From there, The excel takes > all the things as they are and some of my small numbers are shown with the > 'e' on the excel sheet. Which I am trying to avoid. > > I don't need 100 numbers after the comma. What I need is a reasonable amount > of decimal numbers to show that the number is small enough, also keeping them > in float64, in my case to save them into excel file. One important thing to > say is that, if I convert them into string and save them on excel they come > with 'dot' instead of comma. And If try to translate the 'dot' manually into > 'comma' the excel gives warning message to turn those inputs into numbers. > Which I also avoid. > > If this is Python default, showing all numbers smaller than 0.0001 with 'e' > and there is no way to have them in both a human readable and excel savable > form. > You're conflating the number with its representation. Whenever you display a number, you need a set of digits. The number itself is exactly the same whether it's written as 0.0001 or 1e-8 or any other form, just as you can write a fraction as 3 1/7 or as 22/7 and it's the same number. Look at the way you're "saving the result into an Excel file". Firstly, is it CSV or actually saved into Excel format? Then look at the way you actually display the number there. In a CSV file, once again, you need a series of digits, so you simply need to format the number the way that people have been advising you. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert a scientific notation to decimal number, and still keeping the data format as float64
On 10/18/19 9:45 AM, doganad...@gmail.com wrote: > On Friday, October 18, 2019 at 4:17:51 PM UTC+3, Richard Damon wrote: >> On 10/18/19 9:03 AM, doganad...@gmail.com wrote: >>> On Friday, October 18, 2019 at 2:21:34 PM UTC+3, Richard Damon wrote: On 10/18/19 4:35 AM, doganad...@gmail.com wrote: > Here is my question: > > > I am using the numpy.std formula to calculate the standart deviation. > However, the result comes as a number in scientific notation. > Therefore I am asking, How to convert a scientific notation to decimal > number, and still keep the data format as float64 ? > > Or is there any workaround to get the initial standart deviation result > as a decimal number? > > > Here is my code: > > stdev=numpy.std(dataset) > print(stdev) > Result: 4.449e-05 > > > print(stdev.dtype) > Result: float64 > > > Solutions such as this: > > stdev=format(stdev, '.10f') > converts the data into a string object! which I don't want. > > > Expected result: I am willing to have a result as a decimal number in a > float64 format. > > System: (Python 3.7.4 running on Win10) > > > Regards, The number itself isn't in scientific notation or a fixed point number, but is a floating point number that is expressed internally as an integer times a power of 2 (that is the basic representation format for floating point). Scientific notation vs fixed point notation is purely an OUTPUT configuration, not a function on how the number is stored (so in one sense IS more closely linked to a string than the float itself). -- Richard Damon >>> Hello Richard, >>> >>> You seem so right. But what will we do with those strings with 'e' in it? >>> >>> There are ways to present those in a 'normal' way with formatting. However, >>> the result of those formatting turns them into str object and which limits >>> you to do any further numerical things with them. >>> >>> Another thing which I have observed, while doing some experimental thing is >>> that: >>> >> 0.0 >>> 0.0 >>> >> 0.1 >>> 0.1 >>> >> 0.01 >>> 0.01 >>> >> 0.001 >>> 0.001 >>> >> 0.0001 >>> 0.0001 >>> >> 0.1 >>> 1e-05 >>> >>> Again another thing with 1e-05! instead of 0.1 , Is there anything I >>> can do about it? >> The 'e' is only part of the string representation presentation of the >> value. By default, python decides to present small numbers in >> exponential format. If you don't like that, when you print the numbers >> specify the format YOU want, rather than taking the default. >> >> Note, that print() by necessity converts an objects value to a string, >> and this conversion for floats uses exponential notation by default for >> small numbers. If you don't like it, then use an explicit format for the >> conversion. >> >> An alternative might be to change from using a float64 to making it >> something like a Decimal. >> >> -- >> Richard Damon > > By taking the default OUTPUT of a numpy formula, in my case standart > deviation, I am using the advantage of saving the result into an excel file > without any problems.(they come as numpy.float64) From there, The excel takes > all the things as they are and some of my small numbers are shown with the > 'e' on the excel sheet. Which I am trying to avoid. > > I don't need 100 numbers after the comma. What I need is a reasonable amount > of decimal numbers to show that the number is small enough, also keeping them > in float64, in my case to save them into excel file. One important thing to > say is that, if I convert them into string and save them on excel they come > with 'dot' instead of comma. And If try to translate the 'dot' manually into > 'comma' the excel gives warning message to turn those inputs into numbers. > Which I also avoid. > > If this is Python default, showing all numbers smaller than 0.0001 with 'e' > and there is no way to have them in both a human readable and excel savable > form. > > what sould I do? > > Should I consider using another programming language? > > If yes, then this language could be callable from within python and I might > do things I can. The problem is you are thinking of your floating point number as storing something like 5e-5 or 0.5, it doesn't. it store something more like 1.6384 x 2**15 (or some really big 50 some bit integer time a different power of 2). As your words said, it SHOWS it with an e, but that isn't what is in the number. The number is just a number represented as a float. If you don't what to print them with the e, then format them when you print to be the way you want. As to the excel, you aren't being very clear about how you are generating the excel file. If you are directly generating an .xls file, then I believe you want to store the float64 value directly into it, and their is no dot/comm
Asking for feedback: Mirror GitHub issues with a static site generator
Hello, I'm looking to get some feedback on my project. It's a backup mechanism for GitHub issues and pull requests that creates human-readable issue archives in HTML - ready to be served as a static web site. The project is written in Python and works by extending Pelican static site generator, it provides Makefiles for quickly starting with demo configuration. Here are the links: - Home page and documentation: https://issyours.ml/ - Source code: https://github.com/sio/issyours - Demo output: https://issyours.ml/demo/issues/ - Some rationale on why this project was started: https://issyours.ml/design/ What do you think of the project idea? Would that be useful to you or anyone you know? How is documentation? Is it good enough for new users to get started? What about demo instance? Does it show enough to spark interest? Also, if you have time, any feedback on code/architecture would be very appreciated! Thanks! -- Vitaly -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert a scientific notation to decimal number, and still keeping the data format as float64
On Friday, October 18, 2019 at 4:55:33 PM UTC+3, Chris Angelico wrote: > On Sat, Oct 19, 2019 at 12:51 AM wrote: > > By taking the default OUTPUT of a numpy formula, in my case standart > > deviation, I am using the advantage of saving the result into an excel file > > without any problems.(they come as numpy.float64) From there, The excel > > takes all the things as they are and some of my small numbers are shown > > with the 'e' on the excel sheet. Which I am trying to avoid. > > > > I don't need 100 numbers after the comma. What I need is a reasonable > > amount of decimal numbers to show that the number is small enough, also > > keeping them in float64, in my case to save them into excel file. One > > important thing to say is that, if I convert them into string and save them > > on excel they come with 'dot' instead of comma. And If try to translate the > > 'dot' manually into 'comma' the excel gives warning message to turn those > > inputs into numbers. Which I also avoid. > > > > If this is Python default, showing all numbers smaller than 0.0001 with 'e' > > and there is no way to have them in both a human readable and excel savable > > form. > > > > You're conflating the number with its representation. Whenever you > display a number, you need a set of digits. The number itself is > exactly the same whether it's written as 0.0001 or 1e-8 or any > other form, just as you can write a fraction as 3 1/7 or as 22/7 and > it's the same number. > > Look at the way you're "saving the result into an Excel file". > Firstly, is it CSV or actually saved into Excel format? Then look at > the way you actually display the number there. In a CSV file, once > again, you need a series of digits, so you simply need to format the > number the way that people have been advising you. > > ChrisA Thank you Chris, I will answer down below, on Richard's -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert a scientific notation to decimal number, and still keeping the data format as float64
On Friday, October 18, 2019 at 5:53:24 PM UTC+3, Richard Damon wrote: > On 10/18/19 9:45 AM, doganad...@gmail.com wrote: > > On Friday, October 18, 2019 at 4:17:51 PM UTC+3, Richard Damon wrote: > >> On 10/18/19 9:03 AM, doganad...@gmail.com wrote: > >>> On Friday, October 18, 2019 at 2:21:34 PM UTC+3, Richard Damon wrote: > On 10/18/19 4:35 AM, doganad...@gmail.com wrote: > > Here is my question: > > > > > > I am using the numpy.std formula to calculate the standart deviation. > > However, the result comes as a number in scientific notation. > > Therefore I am asking, How to convert a scientific notation to decimal > > number, and still keep the data format as float64 ? > > > > Or is there any workaround to get the initial standart deviation result > > as a decimal number? > > > > > > Here is my code: > > > > stdev=numpy.std(dataset) > > print(stdev) > > Result: 4.449e-05 > > > > > > print(stdev.dtype) > > Result: float64 > > > > > > Solutions such as this: > > > > stdev=format(stdev, '.10f') > > converts the data into a string object! which I don't want. > > > > > > Expected result: I am willing to have a result as a decimal number in a > > float64 format. > > > > System: (Python 3.7.4 running on Win10) > > > > > > Regards, > The number itself isn't in scientific notation or a fixed point number, > but is a floating point number that is expressed internally as an > integer times a power of 2 (that is the basic representation format for > floating point). > > Scientific notation vs fixed point notation is purely an OUTPUT > configuration, not a function on how the number is stored (so in one > sense IS more closely linked to a string than the float itself). > > -- > Richard Damon > >>> Hello Richard, > >>> > >>> You seem so right. But what will we do with those strings with 'e' in it? > >>> > >>> There are ways to present those in a 'normal' way with formatting. > >>> However, the result of those formatting turns them into str object and > >>> which limits you to do any further numerical things with them. > >>> > >>> Another thing which I have observed, while doing some experimental thing > >>> is that: > >>> > >> 0.0 > >>> 0.0 > >>> > >> 0.1 > >>> 0.1 > >>> > >> 0.01 > >>> 0.01 > >>> > >> 0.001 > >>> 0.001 > >>> > >> 0.0001 > >>> 0.0001 > >>> > >> 0.1 > >>> 1e-05 > >>> > >>> Again another thing with 1e-05! instead of 0.1 , Is there anything I > >>> can do about it? > >> The 'e' is only part of the string representation presentation of the > >> value. By default, python decides to present small numbers in > >> exponential format. If you don't like that, when you print the numbers > >> specify the format YOU want, rather than taking the default. > >> > >> Note, that print() by necessity converts an objects value to a string, > >> and this conversion for floats uses exponential notation by default for > >> small numbers. If you don't like it, then use an explicit format for the > >> conversion. > >> > >> An alternative might be to change from using a float64 to making it > >> something like a Decimal. > >> > >> -- > >> Richard Damon > > > > By taking the default OUTPUT of a numpy formula, in my case standart > > deviation, I am using the advantage of saving the result into an excel file > > without any problems.(they come as numpy.float64) From there, The excel > > takes all the things as they are and some of my small numbers are shown > > with the 'e' on the excel sheet. Which I am trying to avoid. > > > > I don't need 100 numbers after the comma. What I need is a reasonable > > amount of decimal numbers to show that the number is small enough, also > > keeping them in float64, in my case to save them into excel file. One > > important thing to say is that, if I convert them into string and save them > > on excel they come with 'dot' instead of comma. And If try to translate the > > 'dot' manually into 'comma' the excel gives warning message to turn those > > inputs into numbers. Which I also avoid. > > > > If this is Python default, showing all numbers smaller than 0.0001 with 'e' > > and there is no way to have them in both a human readable and excel savable > > form. > > > > what sould I do? > > > > Should I consider using another programming language? > > > > If yes, then this language could be callable from within python and I might > > do things I can. > > The problem is you are thinking of your floating point number as storing > something like 5e-5 or 0.5, it doesn't. it store something more like > 1.6384 x 2**15 (or some really big 50 some bit integer time a different > power of 2). As your words said, it SHOWS it with an e, but that isn't > what is in the number. The number is just a number represented as a float. >
Print formatting
Hello, I am new to python and trying to write a script that outputs some data about users. I was able to write it and dump the data but can't seem to align the output in column 2 correctly. Here is what I am trying to do: -- output: user1 data1 username2 data2 user3 data3 snip from script: print(str(temp_list[0]) + "\t\t" + str(temp_list[1])) -- Adding the tabs does not seem to work and I am sure there is a better way to do this. Any help would be appreciated. Thanks, -J -- https://mail.python.org/mailman/listinfo/python-list
Re: Print formatting
On 2019-10-18 18:03, Jagga Soorma wrote: Hello, I am new to python and trying to write a script that outputs some data about users. I was able to write it and dump the data but can't seem to align the output in column 2 correctly. Here is what I am trying to do: -- output: user1 data1 username2 data2 user3 data3 snip from script: print(str(temp_list[0]) + "\t\t" + str(temp_list[1])) -- Adding the tabs does not seem to work and I am sure there is a better way to do this. Any help would be appreciated. A tab advances the output position to the next tab stop, but there's no universal standard for where those tab stops are, although they're commonly at every 8 characters, assuming a monospaced (fixed-width) font. In your example, if the tabs are at every 8 characters then you'll get: | | <= The tab positions user1 data1 username2 data2 user3 data3 "username2" has already passed the first tab, so it advances to the second tab, causing the misalignment. The simplest solution, if you're using a monospaced font, is to use spaces instead. Find the width of the first column (the longest entry in the first column is 9 characters) and then pad all of the first entries with spaces to that width (use string formatting or the .just method) when outputting each line. -- https://mail.python.org/mailman/listinfo/python-list
Re: Print formatting
I seem to have found a way to do this with the following: print('{:<12s}{:>12s}'.format((temp_list[0]),(temp_list[3]))) Still let me know if there is a better way to format this output :) Thanks, -J On Fri, Oct 18, 2019 at 10:03 AM Jagga Soorma wrote: > > Hello, > > I am new to python and trying to write a script that outputs some data > about users. I was able to write it and dump the data but can't seem > to align the output in column 2 correctly. Here is what I am trying > to do: > > -- > output: > user1 data1 > username2 data2 > user3 data3 > > snip from script: > print(str(temp_list[0]) + "\t\t" + str(temp_list[1])) > -- > > Adding the tabs does not seem to work and I am sure there is a better > way to do this. Any help would be appreciated. > > Thanks, > -J -- https://mail.python.org/mailman/listinfo/python-list
python2 vs python3
Hello, I am writing my second python script and got it to work using python2.x. However, realized that I should be using python3 and it seems to fail with the following message: -- Traceback (most recent call last): File "test_script.py", line 29, in test_cmd = ("diskcmd -u " + x + " | grep -v '\*' | awk '{print $1, $3, $4, $9, $10}'" ) TypeError: Can't convert 'bytes' object to str implicitly -- I then run this command and save the output like this: -- test_info = (subprocess.check_output( test_cmd, stderr=subprocess.STDOUT, shell=True )).splitlines() -- Looks like the command output is in bytes and I can't simply wrap that around str(). Thanks in advance for your help with this. -- https://mail.python.org/mailman/listinfo/python-list
Re: Asking for feedback: Mirror GitHub issues with a static site generator
On Sat, Oct 19, 2019 at 2:25 AM Vitaly Potyarkin wrote: > It's a backup mechanism for GitHub issues and pull requests that creates > human-readable issue archives in HTML - ready to be served as a static web > site. The project is written in Python and works by extending Pelican > static site generator, it provides Makefiles for quickly starting with demo > configuration. A good plan. I'm personally (and currently) happy with GitHub, but I'm aware that not everyone is, and of course we don't know what the future holds. > What do you think of the project idea? Would that be useful to you or > anyone you know? Merely by existing, it has value. (Although it would have to be perpetually maintained in order to retain that.) It proves that use of GitHub Issues does not imply that you're locked into the platform, and as such, it's the elimination of an argument against the platform. > Also, if you have time, any feedback on code/architecture would be very > appreciated! You mention a persistent Storage, merely in passing. I want to see more about that. If that storage format is a nice easy thing to work with (eg a set of JSON files), and is a documented and forward/backward-compatible format, it could become a de facto interchange format. Even though THIS project never claims to be able to push back into any issue tracker, some OTHER project could pick up that side of it, and voila, you have a straight-forward backup or transfer format. What are the consequences of using the AGPL for this? If this project is used to create a viewable/searchable issue display, does that mean that the issues themselves are covered by the AGPL, or are they counted as data? I'm hoping it's the latter, but IANAL and I wouldn't want to get bitten by something unexpected. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: python2 vs python3
On Sat, Oct 19, 2019 at 5:29 AM Jagga Soorma wrote: > > Hello, > > I am writing my second python script and got it to work using > python2.x. However, realized that I should be using python3 and it > seems to fail with the following message: > > -- > Traceback (most recent call last): > File "test_script.py", line 29, in > test_cmd = ("diskcmd -u " + x + " | grep -v '\*' | awk '{print $1, > $3, $4, $9, $10}'" ) > TypeError: Can't convert 'bytes' object to str implicitly > -- > > I then run this command and save the output like this: > > -- > test_info = (subprocess.check_output( test_cmd, > stderr=subprocess.STDOUT, shell=True )).splitlines() > -- > > Looks like the command output is in bytes and I can't simply wrap that > around str(). Thanks in advance for your help with this. That's correct. The output of the command is, by default, given to you in bytes. But most likely, they're bytes in some well-known encoding - probably UTF-8 - so you should be able to just tell check_output this, and it'll give you text back. Just add another parameter: subprocess.check_output(test_cmd, stderr=subprocess.STDOUT, shell=True, encoding="utf8") In general, the way to turn bytes into text is to decode them, using some named encoding. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert a scientific notation to decimal number, and still keeping the data format as float64
On 18/10/2019 10:35, doganad...@gmail.com wrote: Here is my question: I am using the numpy.std formula to calculate the standart deviation. However, the result comes as a number in scientific notation. Therefore I am asking, How to convert a scientific notation to decimal number, and still keep the data format as float64 ? Or is there any workaround to get the initial standart deviation result as a decimal number? Here is my code: stdev=numpy.std(dataset) print(stdev) Result: 4.449e-05 print(stdev.dtype) Result: float64 Solutions such as this: stdev=format(stdev, '.10f') converts the data into a string object! which I don't want. Expected result: I am willing to have a result as a decimal number in a float64 format. Float64 is a binary number format, not a decimal format. What you ask can't be done. As to what you want: For most purposes, you can think of the float64 object storing the Platonic ideal of the number, not any particular representation of it. 0.5 and 5E-5 are the same number. End of story. If you want to work with the number, you don't care what it looks like. If you want to display the number, you do care what it looks like, and you want a str rather than a float. System: (Python 3.7.4 running on Win10) Regards, -- https://mail.python.org/mailman/listinfo/python-list
Re: Print formatting
On 10/18/19 2:21 PM, Jagga Soorma wrote: I seem to have found a way to do this with the following: print('{:<12s}{:>12s}'.format((temp_list[0]),(temp_list[3]))) Still let me know if there is a better way to format this output :) I would start with removing the redundant parens. print('{:<12s}{:>12s}'.format(temp_list[0],temp_list[3])) But then I would simplify it further. print('{0[0]:<12s}{0[3]:>12s}'.format(temp_list)) You can do a similar thing with dictionaries. print('{0[data0]:<12s}{0[data3]:>12s}'.format(temp_dict)) You can even mix and match. print('{0[0]:<12s}{1[data3]:>12s}'.format(temp_list, temp_dict)) Finally, if this is in a loop do this. FMT = '{0[0]:<12s}{0[3]:>12s}'.format for temp_list in GetLists(): print FMT(temp_list) Cheers. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:da...@vex.net VoIP: sip:da...@vybenetworks.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Print formatting
On 10/18/19 5:00 PM, D'Arcy Cain wrote: Finally, if this is in a loop do this. FMT = '{0[0]:<12s}{0[3]:>12s}'.format for temp_list in GetLists(): print FMT(temp_list) Oops. Time warp. I meant "print(FMT(temp_list)) -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:da...@vex.net VoIP: sip:da...@vybenetworks.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Instantiating sub-class from super
On 16/10/19 6:33 PM, Frank Millman wrote: On 2019-10-14 10:55 PM, DL Neil via Python-list wrote: Is there a technique or pattern for taking a (partially-) populated instance of a class, and re-creating it as an instance of one of its sub-classes? Here is a link to an article entitled 'Understanding Hidden Subtypes'. It dates back to 2004, but I think it is still relevant. It addresses precisely the issues that you raise, but from a data-modelling perspective, not a programming one. http://tdan.com/understanding-hidden-subtypes/5193 I found it invaluable, and applied the concepts in my own business/accounting application. Having created the ability to make subtypes visible and explicit, I found all kinds of unexpected uses for them. The article seems to be missing a couple of images (Figure 1 and Figure 2) showing the data relationships. I downloaded the original article onto my computer years ago, and my local copy does have the images, so if you would like to see them let me know and I will upload my version somewhere to make it accessible. Superb! Yes please Frank - I've also approached it from the data/DB side, and thus presumably why I was puzzling over how one implements in Python. (alternatively, email a PDF/similar directly) -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: Instantiating sub-class from super
On 17/10/19 4:08 AM, Piet van Oostrum wrote: DL Neil writes: That said, if a "trans" person has ovaries or testes (for example) then a non-traditional sexual identification is irrelevant - for medical purposes. Diseases in those areas (and now I'm a long way from a research questionnaire and from Python - but this is roughly how it was explained to me) still apply, and sadly, may in-fact be considerably complicated by any medical processes that may have contributed to a transition. So what if a person has both ovaries and testes? It is better to keep all options open rather than making hasty subdivisions. Exactly! The objective is not to sub-divide, but to ensure that those to whom various questions are relevant have their answers recorded, but those for whom the section is irrelevant are not over-burdened. In this context that means attributes (that can be None) rather than subclasses. Which seems to be the way we're headed... Thanks! -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: Instantiating sub-class from super
On 17/10/19 7:52 AM, MRAB wrote: On 2019-10-16 19:43, duncan smith wrote: On 16/10/2019 04:41, DL Neil wrote: On 16/10/19 1:55 PM, duncan smith wrote: On 15/10/2019 21:36, DL Neil wrote: On 16/10/19 12:38 AM, Rhodri James wrote: On 14/10/2019 21:55, DL Neil via Python-list wrote: ... So, yes, the "label" is unimportant - except to politicians and statisticians, who want precise answers from vague collections of data... (sigh!) [snip] No not (real) statisticians. People often want us to provide precise answers, but they don't often get them. "It ain’t what you don’t know that gets you into trouble. It’s what you know for sure that just ain’t so." (Mark Twain - perhaps) +1 Although, you've undoubtedly heard people attempt to make claims of having 'accurate figures' (even, "that came from Stats") when you told them that the limitations and variations rendered the exercise laughable... My favorite (of the moment) is a local computer store who regularly offer such gems as: (underneath the sales (web-) page for an upmarket *desktop* computer) "people who bought this also bought" followed by at least two portable PC carry cases. They must be rather large carry-bags! (along with such surprises as keyboard, mouse, ...) This morning I turned-down a study for a political group. One study has already been completed and presented. The antagonist wanted an A/B comparison (backing his 'side', of course). I mildly suggested that I would do it, if he'd also pay me to do an A/B/C study, where 'C' was a costing - the economic opportunity cost of 'the people' waiting for 'the government' to make a decision - (and delaying that decision by waiting for "study" after "study" - The UK and their (MPs') inability to decide "Brexit" a particularly disastrous illustration of such) Sorry, don't want to incur the anger of the list-gods - such calculations would be performed in Python (of course) Clearly, all such analyses should be done in Python. Thank God for rpy2, otherwise I'd have to write R code. It's bad enough having to read it occasionally to figure out what's going on under the hood (I like everything about R - except the syntax). > I have too many examples of people ignoring random variation, testing hypotheses on the data that generated the hypotheses, shifting the goalposts, using cum / post hoc ergo propter hoc reasoning, assuming monocausality etc. In some areas these things have become almost standard practice (and they don't really hinder publication as long as they are even moderately well hidden). Of course, it's often about policy promotion, and the economic analyses can be just as bad (e.g. comparing the negative impacts of a policy on the individual with the positive impacts aggregated over a very large population). And if it's about policy promotion a press release is inevitable. So we just need to survey the news media for specific examples. Unfortunately there's no reliable service for telling us what's crap and what isn't. (Go on, somebody pay me, all my data processing / re-analysis will be in Python ;-).) Even when using Python, you have to be careful: Researchers find bug in Python script may have affected hundreds of studies https://arstechnica.com/information-technology/2019/10/chemists-discover-cross-platform-python-scripts-not-so-cross-platform/ I think both of our 'Python' comments were made tongue-in-cheek. Sadly the tool won't guarantee the result... At my first research project, before I'd even completed my first degree, I noticed a similar fault in some code*. There was I, the youngest, newest, least-est member of staff, telling the prof/boss and all the other researchers that they'd made a serious error, upon which various papers had been based plus a white-paper for government consideration. Oops! (Basic-Plus on DEC PDP/Vax-en introduced a 'virtual storage array', ie on-disk cf in-RAM. However, it did not wipe the disk-space prior to use (whereas arrays were zero-ed, IIRC). Thus, random data purporting to be valid data-entered. Once corrected and re-run "my results" (as they were termed - not sure if insult or compliment) were not hugely different from the originals). All we can do, is add some checks-and-balances rather than relying on 'the computer'. Upon which point: those of us who learned 'complicated math' with the aid of a slide-rule, employ a technique of mentally estimating the result in both the first first few digits and scale - and thus noticing any completely incongruous 'result'. Even with lessons in "The Scientific Approach" am not aware that the 'calculator' or 'computer generations' were/are taught such 'common sense'... -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: Instantiating sub-class from super
On 18/10/19 9:27 AM, Eryk Sun wrote: On 10/17/19, MRAB wrote: On 2019-10-17 20:06, Eryk Sun wrote: I'm bugged by how the article mis-characterizes the fundamental problem. The operating system has nothing to do with the order of a directory listing, which varies even with an OS, depending on the file system. The latter could store each entry in a tree structure that's sorted by filename, or it could use a mapping with hash values, or it could simply use the first available slot in a list, based on the order of past create and delete operations. "The operating system has nothing to do with the order of a directory listing"? Well, that depends on the operating system. It might guarantee the order. That would be typically provide no benefit and be an unnecessary expense in the kernel, especially for directories that contain thousands of entries, considering applications typically need a particular sort order anyway. Also, while such a system could make this default order cheap for its own platform-restricted file systems, supporting other file systems such as NTFS and ext3 would bear the cost of having to dynamically sort directory listings instead of just listing the entries as they're naturally stored in the file-system data structures. To be fair to the original developers, not many people develop with multiple platforms in-mind. Perhaps more *nix devs do think 'platform' because the user-community may be MS-Win-based... When building an application, if it works for you, that's great. If others then want to use it, there is an amount of "caveat emptor" - particularly when jumping platforms. With the gift of hind-sight, some ideas may seem weak, even reprehensible; but they worked at the time. Just this morning I was reading about 'legal' Linux file/path syntax, and saw an article which recounted that Bourne (as in -Shell) had a series of files - one for each of the legal characters, which could be used as some sort of lookup. Are there easier ways once RAM has become cheap(er)? NB have no idea of the veracity of this claim. I've been working on a consolidation of personal file/dir-manipulation utilities (as many 'here' know, and have kindly guided/assisted) but have not given any thought to non-Posix systems at all (contrary to the aims of importlib, for example). If someone takes *my* code and tries to run it on MS-Win Python, they'll soon find-out! That said, I'm not expecting to publish any results with the expectation of world-domination... -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
A news aggregator for the Python community
Hi! Over the last few weeks I've build a hacker news clone for the Python community: https://news.python.sc The source is at github.com/sebst/pythonic-news I thought that might be of interest to you and I'd be more than happy to hear your thoughts on this. Best, --Sebastian -- https://mail.python.org/mailman/listinfo/python-list