Broadcast array multiplication in Fortran 90/95

拜拜、爱过 提交于 2019-11-29 10:57:36

The expression

a * SPREAD(b,1,3)

will produce the same result as your loop. I'll leave it to you and to others to judge whether this is more succinct or in any way better than the loop.

The do loop can be replaced by a one-liner using FORALL:

forall (i=1:3) a(:, i) = a(:, i) * b(i)

If you are reusing a particular b frequently you could define:

 b(3, 3)=reshape([1, 1, 1, 2, 2, 2, 3, 3, 3], [3, 3])

then you just can do:

 a=a*b

..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!