Q: 依照矩陣元素位置轉換
Ans:
A = RandomInteger[100, {6, 6}]
transform[ma_List]:=Block[{myrule,tran},
(*轉換規則*)
myrule={{44,12,53,14,15,62},{21,22,23,43,25,26},
{31,13,33,34,35,36},{41,42,11,24,45,46},
{51,52,32,16,54,56},{61,55,63,64,65,66}};
(*取出對應位置元素*)
tran=ToExpression@
Flatten[Table[{StringTake[ToString[myrule[[i,j]]],1],
StringTake[ToString[myrule[[i,j]]],-1]},{i,6},{j,6}],1];
(*重新排列*)
Partition[ma[[#[[1]],#[[2]]]]&/@tran,6]]
(* test *)
transform[A] // MatrixForm
讀者回應 ( 0 意見 )
訂閱發佈留言 (Atom)
發佈留言
Please leave your name and tell me what you thought about this site. Comments, suggestions and views are welcomed.
如果這篇文章對你有幫助,那請留個訊息給我~