Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review use of numpy.arange() to define t array #5

Open
ncclementi opened this issue Dec 11, 2017 · 0 comments
Open

Review use of numpy.arange() to define t array #5

ncclementi opened this issue Dec 11, 2017 · 0 comments

Comments

@ncclementi
Copy link
Member

Same dt in both cases, The last element is supposed not to be inclusive, Why in the first case works and in the second doesn't? Any idea?

In [16]: dt = 0.005

In [17]: t1=numpy.arange(0, 50.005, dt)

In [18]: t1[-1]
Out[18]: 50.0

In [19]: t2=numpy.arange(0, 10.005, dt)

In [20]: t2[-1]
Out[20]: 10.005000000000001

According to numpy.arange documentation:

For floating point arguments, the length of the result is ceil((stop - start)/step). Because of floating point overflow, this rule may result in the last element of out being greater than stop.

caso a) numpy.ceil((stop - start)/dt) returns 10001.0

caso b) numpy.ceil((stop - start)/dt) returns 2002.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant