Skip to content

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

@ncclementi

Description

@ncclementi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions