Is there a function like a F#’s Seq.scan() in Python?
I want to do some cumsum() or cumproduct() kind of things without looping.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Ignacio’s solution is almost right I think, but requires a operator of type (‘a -> ‘a -> ‘a) and doesn’t yield the first element.
Specifically, the type of
Seq.scanisThe default approach in Python is to write a
scanwith the typeThis comes from the way that Python specifies
reduce, which has the same type by default.