Matlab相当于Numpy广播? [英] Matlab equivalent of Numpy broadcasting?

查看:99
本文介绍了Matlab相当于Numpy广播?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种方法,从Matlab中3 *(大量)矩阵的每一列中减去3号矢量.当然,我可以使用循环,但是我正在尝试找到一些更有效的解决方案,有点像numpy广播.哦,我不能使用repmat,因为我没有足够的内存来使用它(因为它创建了另一个3 *(大数字)矩阵)...

这可能吗?

解决方案

由于 bsxfun 可能会解决问题但是,根据我的经验,它通常也有内存问题,但少于repmat.

因此语法为:

AA = bsxfun(@minus,A,b),其中b是向量,A是您的大矩阵

但是,我恳请您介绍有毛病的版本,然后再决定!很可能由于内存限制,您可能没有选择:)

I'm trying to find some way to substract a size 3 vector from each column of a 3*(a big number) matrix in Matlab. Of course I could use a loop, but I'm trying to find some more efficient solution, a bit like numpy broadcasting. Oh, and I can't use repmat because I just don't have enough memory to use it (as it creates yet another 3*(a big number) matrix)...

Is this possible?

解决方案

Loops aren't bad in MATLAB anymore thanks to compiler optimizations like just-in-time acceleration (JITA). etc. Most of the time, I've noticed that a solution with loops in current MATLAB versions is much faster than complicated (albeit, cool :D) one-liners.

bsxfun might do the trick but in my experience, it tends to have memory issues as well but less so than repmat.

So the syntax would be:

AA = bsxfun(@minus,A,b) where b is the vector and A is your big matrix

But I urge you to profile the loopy version and then decide! Most probably, due to memory constraints, you might not have a choice :)

这篇关于Matlab相当于Numpy广播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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