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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy