Skip to content

cumsum (and accumulation operators generally?) should have an option to leave the identity in the first spot #6044

@njsmith

Description

@njsmith

I just found myself writing:

points_on_path = ...
point_to_point_distances = np.hypot(points_on_path[1:, :], point_ons_path[:-1, :])
arclengths = np.cumsum(point_to_point_distances)
arclengths = np.concatenate(([0], arclengths)
# now arclengths.shape == points_on_path.shape

and it occured to me that this is definitely not the first time I've found myself doing the awkward concatenate-a-zero dance in order to get a cumsum array whose shape matches what I want. Maybe we should have a convenience argument to cumsum (and to ufunc.accumulate in general I guess) to insert the operation's identity as the first argument.

No brain to figure out the details of how this would work right now, but filing a bug to remind me/us...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions