문제

Is there standard implementation of fold (reduce, aggregate etc) for one dimensional vector in Octave? If no, is there any way to express fold without using a loop statement?

도움이 되었습니까?

해결책

The miscellaneous package provides the function reduce. For example,

octave:6> reduce(@(x,y)(x*y), [1:5])
ans =  120

If you look at the source code for reduce, you'll see that it is a fairly simple Octave function that is implemented with a for loop, so it won't be more efficient than implementing the reduction with a for loop of your own.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top