MapThread 用于任意变量组合

发布于 2024-11-02 02:54:00 字数 431 浏览 1 评论 0原文

我有一组正则(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸里的快感 2024-11-09 02:54:00

我不确定我是否理解你的问题,但如果你的目的是获得两个矩阵 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}

演出会有结束 2024-11-09 02:54:00

在这种情况下,您需要Outer

In[27]:= n = RandomInteger[{1, 5}, {3, 2, 2}];

In[28]:= Outer[mFunc, n, n, 1]

Out[28]= {{mFunc[{{3, 5}, {2, 4}}, {{3, 5}, {2, 4}}], 
  mFunc[{{3, 5}, {2, 4}}, {{3, 4}, {4, 3}}], 
  mFunc[{{3, 5}, {2, 4}}, {{4, 4}, {5, 1}}]}, {mFunc[{{3, 4}, {4, 
     3}}, {{3, 5}, {2, 4}}], 
  mFunc[{{3, 4}, {4, 3}}, {{3, 4}, {4, 3}}], 
  mFunc[{{3, 4}, {4, 3}}, {{4, 4}, {5, 1}}]}, {mFunc[{{4, 4}, {5, 
     1}}, {{3, 5}, {2, 4}}], 
  mFunc[{{4, 4}, {5, 1}}, {{3, 4}, {4, 3}}], 
  mFunc[{{4, 4}, {5, 1}}, {{4, 4}, {5, 1}}]}}

In[29]:= n

Out[29]= {{{3, 5}, {2, 4}}, {{3, 4}, {4, 3}}, {{4, 4}, {5, 1}}}

In this case you need Outer:

In[27]:= n = RandomInteger[{1, 5}, {3, 2, 2}];

In[28]:= Outer[mFunc, n, n, 1]

Out[28]= {{mFunc[{{3, 5}, {2, 4}}, {{3, 5}, {2, 4}}], 
  mFunc[{{3, 5}, {2, 4}}, {{3, 4}, {4, 3}}], 
  mFunc[{{3, 5}, {2, 4}}, {{4, 4}, {5, 1}}]}, {mFunc[{{3, 4}, {4, 
     3}}, {{3, 5}, {2, 4}}], 
  mFunc[{{3, 4}, {4, 3}}, {{3, 4}, {4, 3}}], 
  mFunc[{{3, 4}, {4, 3}}, {{4, 4}, {5, 1}}]}, {mFunc[{{4, 4}, {5, 
     1}}, {{3, 5}, {2, 4}}], 
  mFunc[{{4, 4}, {5, 1}}, {{3, 4}, {4, 3}}], 
  mFunc[{{4, 4}, {5, 1}}, {{4, 4}, {5, 1}}]}}

In[29]:= n

Out[29]= {{{3, 5}, {2, 4}}, {{3, 4}, {4, 3}}, {{4, 4}, {5, 1}}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文