gpt4 book ai didi

c# - c#中的bsxfun类型函数

转载 作者:太空宇宙 更新时间:2023-11-03 21:26:49 25 4
gpt4 key购买 nike

我正在尝试执行与以下 matlab 函数等效的操作:

outmatrix = bsxfun(@minus,inmatrix, invector);

升c。我用过这个:

public static ILArray<double> bsxfun(ILArray<double> inmatrix, ILArray<double> invector)
{

for(int i=0; i < inmatrix.getlength(1) ;i++)
{
inmatrix[":",i] = inmatrix[":",i] -invector;
}
return inmatrix;

}

利用 ILNumerics 包。

我的问题:这是最有效的方法吗?因为我的矩阵可能很大。我如何概括这一点,以便我可以像使用函数句柄一样指定是否执行减号、加号、乘法、除法等操作?

最佳答案

在 ILnumerics 中你不需要做任何事情。 ILNumerics 自动正确地在矩阵元素上操作向量:

 outmatrix = inmatrix - invector; 

文档:http://ilnumerics.net/Opoverload.html

顺便说一句:如果你想要高效的实现,你必须使用 ILNumerics 函数规则:http://ilnumerics.net/FunctionRules.html

关于c# - c#中的bsxfun类型函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26495119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com