X Tutup
Skip to content

histogram and digitize do not agree on the definition of a bin #5367

@jtbraun

Description

@jtbraun

numpy.histogram produces bins such that:

All but the last (righthand-most) bin is half-open. In other words, if bins is:

[1, 2, 3, 4]
then the first bin is [1, 2) (including 1, but excluding 2) and the second [2, 3). The last bin, however, is [3, 4], which includes 4.

numpy.digitize interprets the bin argument as:

Each index i returned is such that bins[i-1] <= x < bins[i] if bins is monotonically increasing, or bins[i-1] > x >= bins[i] if bins is monotonically decreasing.

It would be convenient if numpy.digitize could be configured to interpret bins as the way that numpy.histogram produces them. Maybe change or replace the right argument to be interval=None|'left'|'right'|'leftclosed'|'rightclosed', where 'leftclosed' would behave as numpy.histogram does.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup