倍频中的折叠功能 [英] Fold function in Octave

查看:88
本文介绍了倍频中的折叠功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Octave中的一维矢量是否存在折叠(缩小,聚合等)的标准实现?
如果不是,有什么方法可以在不使用循环语句的情况下表达fold? http://octave.sourceforge.net/miscellaneous/index.html =nofollow> 其他 软件包提供了 reduce 。例如,

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

如果您查看 reduce 的源代码,您会发现它是一个相当简单的Octave函数,它使用 for 循环,所以它不会比用自己的循环执行缩减更有效。


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.

这篇关于倍频中的折叠功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆