Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9000721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:20:45+00:00 2026-06-16T00:20:45+00:00

Is there a function in numpy or scipy (or some other library) that generalizes

  • 0

Is there a function in numpy or scipy (or some other library) that generalizes the idea of cumsum and cumprod to arbitrary function. For example, consider the (theoretical) function

cumf( func, array) 

func is a function that accepts two floats, and returns a float. Particular cases

lambda x,y: x+y 

and

lambda x,y: x*y 

are cumsum and cumprod respectively. For example, if

func = lambda x,prev_x: x^2*prev_x 

and I apply it to:

cumf(func, np.array( 1, 2, 3) )

I would like

np.array( 1, 4, 9*4 )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:20:45+00:00Added an answer on June 16, 2026 at 12:20 am

    NumPy’s ufuncs have accumulate():

    In [22]: np.multiply.accumulate([[1, 2, 3], [4, 5, 6]], axis=1)
    Out[22]: 
    array([[  1,   2,   6],
           [  4,  20, 120]])
    

    Unfortunately, calling accumulate() on a frompyfunc()‘ed Python function fails with a strange error:

    In [32]: uadd = np.frompyfunc(lambda x, y: x + y, 2, 1)
    
    In [33]: uadd.accumulate([1, 2, 3])
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    
    ValueError: could not find a matching type for <lambda> (vectorized).accumulate, 
                requested type has type code 'l'
    

    This is using NumPy 1.6.1 with Python 2.7.3.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a function in numpy/scipy that returns all the elements of one of
Is there a built-in function in scipy/numpy for getting the PMF of a Multinomial?
Is there a function in numpy that determines whether strings should be integers or
Is there function to get an iterator over an arbitrary dimension of a numpy
Is there another way in numpy to realize scipy.stats.mode function to get the most
Given an arbitrary numpy array ( ndarray ), is there a function or a
Is there a numpy function that gives for a given numpy array its maximum
Is there a numpy function (or algorithm) that only returns the items of an
Is there an equivalent Matlab dot function in numpy? The dot function in Matlab:
Is there any built-in function in Python3/Numpy which filters an array and returns indices

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.