正确使用Mathematica中的关联将标签应用于向量



我有一个矩阵,它包含多个带有相关标签的向量。矩阵看起来像这样:

inputseq2s={{0,2,4,6}->"A",{9,7,6,5}->"B",{5,6,4,3}->C}}

然后,我在矩阵上映射一个函数,如下所示:

outtable2=Map[{#[[2]],iterfunc[#[[1]]]}&,inputseq2s];

但是输出看起来是这样的:

{{A,{0,1,0,1}},{B,{0,0,1,1}},{C,{0,0,0,1}}}

我需要它看起来像这样:

{{0,1,0,1}->"A",{0,0,1,1}->"B",{0,0,0,1}->"C"}

但到目前为止,我一直未能弄清楚如何实现这一点。如有任何帮助,我们将不胜感激。

这是完整的代码。我之前没有包括它,因为我认为它可能会搅乱局面,但现在是:

iterfunc=Function[seq2,coltot=Length[Partition[seq1,window,offsetwindowseq1]];
rowtot=Length[Partition[seq2,window,offsetwindowseq2]];
outlabels=Table[wordseqname<>"("<>ToString[If[x<2,x,((x-1)*offsetwindowseq1)+1]]<>"-"<>ToString[((x-1)*offsetwindowseq1)+window]<>")",{x,1,coltot}];
dist1=Tuples[{Partition[seq1,window,offsetwindowseq1],Partition[seq2,window,offsetwindowseq2]}];
outtable=Partition[Table[CanonicalWarpingDistance[dist1[[i,1]],dist1[[i,2]],Automatic,{"SlantedBand",bandwidth},Method->{"MatchingInterval"->"Flexible"},DistanceFunction->distfunc],{i,1,Length[dist1]}],coltot];
normfunc=Function[x,x/window];normtable=Map[normfunc,outtable];
test=Function[x,If[x<=threshold,1,0]];
outtable2=Partition[Map[test,Flatten[normtable],1],coltot];
Total[outtable2]];

您正在将规则的inputseq2列表的元素映射到一个列表,标签在前,interfunc的输出在后。

你可能想要这样的东西:

outtable2 = Map[Rule[interfunc[#[[1]]], #[[2]]] &, inputseq2s]

inputseq2outtable2都是规则列表,而不是关联。

最新更新