Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有 3 个向量,分别命名为 a、b 和 c,我想创建 3D 矩阵 M,因此 M(i,j,k) = a(i) + b(j) + c(k),其中 a( i) 表示向量 a 的第 i 个元素,同样适用于所有向量和矩阵。
对于创建 2d 矩阵,这很简单,就像 a+b'。但我不确定如何创建 3d 矩阵。
你只需要permute或reshape做换位的多维等价物:
permute
reshape
a + b.' + reshape(c, 1, 1, []);
假设 , a,b是c大小为L× 1, M×1和N×的列向量1,这是有效的,因为
a
b
c
L
1
M
N
b.'
reshape(c, 1, 1, []
因此,通过隐式展开,结果是一个L× M× N3D 数组。