Git Product home page Git Product logo

Comments (2)

Kunde21 avatar Kunde21 commented on June 16, 2024

FYI: Reviewing this issue revealed an inconsistency that was fixed in b9dc613.

Some of the numpy arange logic has been a pain point for me and those I've taught/worked with. The issue shows up when working with negative-stepping ranges:

// Dropping stop number (numpy)
np.arange(0, 5)        => [0 1 2 3 4]
np.arange(5, 0, -1)  => [5 4 3 2 1]
np.arange(-5, 0)      => [-5 -4 -3 -2 -1]
np.arange(0, -5, -1) => [0 -1 -2 -3 -4]

// Keeping the stop number (numgo)
numgo.Arange(0, 5)   => [0 1 2 3 4 5]
numgo.Arange(5, 0)   => [5 4 3 2 1 0]
numgo.Arange(-5, 0)  => [-5 -4 -3 -2 -1 0]
numgo.Arange(0, -5)  => [0 -1 -2 -3 -4 -5]

The other part of changing the Arange(0, 5) result is deciding how the Arange(5, 0) result will be changed. There are a couple options that would work like np.arange(0,x), each with related issues:

  • Drop the stop number, which means flipping l/r Arange(0,5) is the less logical call Arange(4, -1). This trips up beginners and experienced numpy users alike.
  • Drop the number with the greatest absolute value, which makes for another question about handling Arange(5, -5) vs Arange(-5, 5). A smaller corner case, meaning a lot more warnings and explanations in the documentation.

While I would like to mirror as much of the numpy API as possible, the handling of negative-stepping ranges is something I felt needed to be re-thought. If you have suggestions on how to improve the API, please keep in mind that numgo.Arange handles negative ranges and increments, which complicates some things. This implementation is just my first attempt at making arange less confusing with negative steps.

from numgo.

ledao avatar ledao commented on June 16, 2024

Thanks for your consideration.
To be honest, I am a numpy user. Keeping or droping 'stop' is not a question, the question is consistency. In len(vals) == 1 condition, numgo drops 'stop', but in len(vals) == 2 condition, numgo keeps 'stop'.
Here is my idea.
I didn't notice that, numgo.Arange(-10) => [-9 -8 -7 -6 -5 -4 -3 -2 -1 0]. In my view, Since -10 is 'stop', and the default 'start' should be 0, then the sequence must be [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] (desc), not [-9 -8 -7 -6 -5 -4 -3 -2 -1 0].
If you agree, we only need to handle 'stop'.
Dropping 'stop': 'stop' -1 in ascending order sequence; 'stop'+1 in descending order sequence.
Keeping 'stop': 'stop' is unchanged in all conditions.
For example:

	case 2:
		if vals[1] < vals[0] {
			step = -1
			start, stop = vals[0], vals[1]+1
		} else {
			start, stop = vals[0], vals[1]-1
		}

Now we just need to handle 'stop', leaving 'start' unchanged.

Thanks.
(Sorry for my English)

from numgo.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.