Matlab函数ndgrid的F#张量等效项

时间:2018-10-11 02:15:25

标签: matlab matrix f# functional-programming linear-algebra

我正在尝试实现一个f#函数,该函数使用DeepML.Net中的f#Tensor库复制matlab函数ndgrid。我是F#和函数式编程风格的新手,并且除了蛮力嵌套循环外,似乎找不到其他解决方案。

我要模拟的matlab代码看起来像下面的代码,但我想支持任意长度的尺寸和尺寸的数量。

a = [0 1];
b = [2 3];
c = [4 5];
d = [6 7];
[A, B, C, D] = ndgrid(a,b,c,d)

哪个输出:

ans(:,:,1,1) =

   0   0
   1   1

ans(:,:,2,1) =

   0   0
   1   1

ans(:,:,1,2) =

   0   0
   1   1

ans(:,:,2,2) =

   0   0
   1   1

B =

ans(:,:,1,1) =

   2   3
   2   3

ans(:,:,2,1) =

   2   3
   2   3

ans(:,:,1,2) =

   2   3
   2   3

ans(:,:,2,2) =

   2   3
   2   3

C =

ans(:,:,1,1) =

   4   4
   4   4

ans(:,:,2,1) =

   5   5
   5   5

ans(:,:,1,2) =

   4   4
   4   4

ans(:,:,2,2) =

   5   5
   5   5

D =

ans(:,:,1,1) =

   6   6
   6   6

ans(:,:,2,1) =

   6   6
   6   6

ans(:,:,1,2) =

   7   7
   7   7

ans(:,:,2,2) =

   7   7
   7   7

Matlab ndgrid文档:https://www.mathworks.com/help/matlab/ref/ndgrid.html

张量F#: http://www.deepml.net/Tensor/

0 个答案:

没有答案