This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: arange from numpy function has some limits....I propose a python function that overcome these limitations
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: Francesco Pelizza, abarry, vstinner
Priority: normal Keywords:

Created on 2016-01-25 12:57 by Francesco Pelizza, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
CYCLE.py Francesco Pelizza, 2016-01-25 12:57 Python executable containing the function I made
Messages (3)
msg258899 - (view) Author: Francesco Pelizza (Francesco Pelizza) * Date: 2016-01-25 12:57
arange from numpy is a function to generate list of floats from a start to an end number with a defined float number.

The "arange" function works fine for some cases, but in my case where I have to generate numbers that constitute parameters in a Quantum Mechanical calculation, numbers can be missing or be more than what I want, since many time each number is calculated in a couple of days or more. I need to avoid extra numbers or missing numbers to avoid loss of data. And sometimes the script will pass to a cycle function wrong numbers for start and stop, or the same number as starting and ending point, but I can not avoid this because they are numbers coming from Quantum World, and I need a function that sort out anything on its own because is inserted in for loops and things like that.

Also arange function does not take the "stop" number as the last number of the list, but it will terminate before, so to have the last wanted number in the list you have to use the formulae  arange(start,stop+inc,inc) or arange(start,stop+n,inc) where n allows is bigger than zero.

Some cases that give me problems are the following:
Defective lists of numbers:
1) arange(1,10+0.0000001,0.00000001) some numbers are missing
2) arange(1,10+0.0000001,1) generate float without any decimal after the point
3) arange(1,10,0.0000001) some numbers are missing
4) ...other combination gives problems

Empty lists of numbers:
1) arange(1,10,-1)
2) arange(1,-10,1)
3) arange(1,1,1)
4) arange(1,1,0.5)
5) arange(1,-10,0.005)
6) so on....

I made a python function that goes across any of these problems, taking account of using the absolute value of the given incremental step number.

Numbers can be float or integers, any exception of number ordering is kept under control to generate anyway at least a list of one number, if the stop number is bigger than the starting one, they get switched to generate anyway a list of numbers. And it can go down until 14 decimal places of incremental steps without generating wrong numbers due to the binary conversion of floats!
Some use of this function are eventually weird or really exotic, but in using python as a code to deal with computation without crashing for silly numbers ordering from the quantum world, is essential.

Do you agree with the improvements I put in this function called "CYCLE" can be of help?

I would like to share it with the community.

Here attached the function I made
msg258900 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-01-25 13:01
It looks like an issue for numpy no? http://www.scipy.org/scipylib/bug-report.html

I'm not sure that such function fits into Python stdlib.
msg258902 - (view) Author: Anilyka Barry (abarry) * (Python triager) Date: 2016-01-25 14:36
NumPy isn't a part of CPython. As haypo said, please submit that to their tracker instead.
History
Date User Action Args
2022-04-11 14:58:26adminsetgithub: 70385
2016-01-25 14:36:26abarrysetstatus: open -> closed

nosy: + abarry
messages: + msg258902

resolution: third party
stage: resolved
2016-01-25 13:01:41vstinnersetnosy: + vstinner
messages: + msg258900
2016-01-25 13:01:30Francesco Pelizzasettitle: arange from numpy function has some limits....I propose a python function that overcome -> arange from numpy function has some limits....I propose a python function that overcome these limitations
2016-01-25 12:57:17Francesco Pelizzacreate