MapThread 用于任意变量组合
我有一组正则(mod 5)矩阵 N2,我想在 Mathematica 中获得由这些矩阵生成的群: 我的方法是使用函数 f 进行矩阵乘法,使用 g 进行模 5,然后我想使用 MapThread
M= Function[{x,y},x.y];
g = Function[z, Mod[z, 5]]
g /@ MapThread[M, {N2,N2}]
问题是 MapThread 仅插入列表中相同位置的元素对。我想在 N 中插入任意一对元素。要获得 NI 中矩阵生成的组,只需重复此操作并每次更新 N2 即可。
例如,让 N2 ={A,B}
g /@ MapThread[M, {N2,N2}]
将返回 {B^2,A^2},而我希望它返回 N2 中矩阵的任何乘积,即 {A^2,AB,BA,B^2}。
I have a set of regular (mod 5) matrices N2 and I would like to get the group generated by these matrices in Mathematica:
My approach was to use a function f doing the matrix multiplication and g for mod 5 and then I wanted to use MapThread
M= Function[{x,y},x.y];
g = Function[z, Mod[z, 5]]
g /@ MapThread[M, {N2,N2}]
The problem is that MapThread is inserting only pairs of elements that are at the same position in the lists. I would like to insert any pair of elements in N. To get the group generated by the matrices in N I would just repeat this and update N2 every time.
E.g. let N2 ={A,B}
g /@ MapThread[M, {N2,N2}]
would return {B^2,A^2}, while I want it to return any product of matrices in N2, i.e. {A^2,AB,BA,B^2}.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我是否理解你的问题,但如果你的目的是获得两个矩阵 A,B 的所有组合,你可以使用 Tuples 与 Apply 结合使用(你可以用方括号或尽可能多的函数形式使用它)以最初神秘的前缀运算符形式 @@@ = 应用在级别 1):
In[24]:= Dot @@@ Tuples[{A, B}, 2]
Out[24]= {AA, AB, BA, BB }
I'm not sure whether I understand your question, but if your intention is to get all combinations of the two matrices A,B you could use Tuples combined with Apply (which you may use in its functional form with square brackets or as many here do in initially cryptic prefix operator form @@@ = Apply at level 1):
In[24]:= Dot @@@ Tuples[{A, B}, 2]
Out[24]= {A.A, A.B, B.A, B.B}
在这种情况下,您需要
Outer
:In this case you need
Outer
: