行列の配列についての質問です。
[I1]が2×3の行列、[J1]が4×3の行列、
[I2]が4×5の行列、[J2]が6×5の行列だとします。
そこで以下のような行列を作成します。
[ [ [I1] , [J1] , 0...]
[ 0 , [I2] , [J2] , 0...]
[ 0 , 0 , [J2] , [I2] , 0...]
~~~~~~~~~~~~~~~~~~~
[ 0 , 0 , 0 , 0... , [J2] , [I2] ] ]
0...は以降の成分は0であることを示しています。
このような行列を作る場合に適切な処理方法はありますか?
今のところ愚直にすべての成分が0の行列を考えて、
繰り返しなどを使い該当部分に成分を代入していくという初歩的な方法しか思いつきません。
何か良い方法があれば教えてください。
具体例を示します。
I1 = [
[1,0],
[1,0],
[0,0] ]
J1 = [
[1,0,0,0],
[0,1,0,0],
[0,0,0,1] ]
I2 = [
[1,0,0,0],
[0,1,0,0],
[0,1,0,0],
[0,0,1,0],
[0,0,0,1] ]
J2 = [
[1,0,0,0,0,0],
[0,1,0,0,0,0],
[0,0,1,0,0,0],
[0,0,0,1,0,0],
[0,0,0,0,0,1] ]
目標の行列を[M]として、n=1の時
[M]=[
[1,0, 1,0,0,0, 0,0,0,0,0,0],
[1,0, 0,1,0,0, 0,0,0,0,0,0],
[0,0, 0,0,0,1, 0,0,0,0,0,0],
[0,0, 1,0,0,0, 1,0,0,0,0,0],
[0,0, 0,1,0,0, 0,1,0,0,0,0],
[0,0, 0,1,0,0, 0,0,1,0,0,0],
[0,0, 0,0,1,0, 0,0,0,1,0,0],
[0,0, 0,0,0,1, 0,0,0,0,0,1] ]
n=2のとき
[M]=[
[1,0, 1,0,0,0, 0,0,0,0,0,0, 0,0,0,0, 0,0,0,0,0,0],
[1,0, 0,1,0,0, 0,0,0,0,0,0, 0,0,0,0, 0,0,0,0,0,0],
[0,0, 0,0,0,1, 0,0,0,0,0,0, 0,0,0,0, 0,0,0,0,0,0],
[0,0, 1,0,0,0, 1,0,0,0,0,0, 0,0,0,0, 0,0,0,0,0,0],
[0,0, 0,1,0,0, 0,1,0,0,0,0, 0,0,0,0, 0,0,0,0,0,0],
[0,0, 0,1,0,0, 0,0,1,0,0,0, 0,0,0,0, 0,0,0,0,0,0],
[0,0, 0,0,1,0, 0,0,0,1,0,0, 0,0,0,0, 0,0,0,0,0,0],
[0,0, 0,0,0,1, 0,0,0,0,0,1, 0,0,0,0, 0,0,0,0,0,0],
[0,0, 0,0,0,0, 1,0,0,0,0,0, 1,0,0,0, 0,0,0,0,0,0],
[0,0, 0,0,0,0, 0,1,0,0,0,0, 0,1,0,0, 0,0,0,0,0,0],
[0,0, 0,0,0,0, 0,0,1,0,0,0, 0,1,0,0, 0,0,0,0,0,0],
[0,0, 0,0,0,0, 0,0,0,1,0,0, 0,0,1,0, 0,0,0,0,0,0],
[0,0, 0,0,0,0, 0,0,0,0,0,1, 0,0,0,1, 0,0,0,0,0,0],
[0,0, 0,0,0,0, 0,0,0,0,0,0, 1,0,0,0, 1,0,0,0,0,0],
[0,0, 0,0,0,0, 0,0,0,0,0,0, 0,1,0,0, 0,1,0,0,0,0],
[0,0, 0,0,0,0, 0,0,0,0,0,0, 0,1,0,0, 0,0,1,0,0,0],
[0,0, 0,0,0,0, 0,0,0,0,0,0, 0,0,1,0, 0,0,0,1,0,0],
[0,0, 0,0,0,0, 0,0,0,0,0,0, 0,0,0,0, 0,0,0,0,0,1] ]
視覚的にわかりやすくするために、値を変えます。
[I1] = [[1,2],[3,4],[5,6]]
[J1] = [[11,12,13,14],[15,16,17,18],[19,20,21,22]]
[I2] = [[31,32,33,34],[35,36,37,38],[39,40,41,42],[43,44,45,46],[47,48,49,50]]
[J2] = [[51,52,53,53,55],[56,57,58,59,60],[61,62,63,64,65],[66,67,68,69,70],[71,72,73,74,75]]
[M]=[
[1,2, 11,12,13,14, 0,0,0,0,0,0, 0, 0, 0, 0, 0,0,0,0,0,0],
[3,4, 15,16,17,18, 0,0,0,0,0,0, 0, 0, 0, 0, 0,0,0,0,0,0],
[5,6, 19,20,21,22, 0,0,0,0,0,0, 0, 0, 0, 0, 0,0,0,0,0,0],
[0,0, 31,32,33,34, 51,52,53,53,55, 0, 0, 0, 0, 0,0,0,0,0,0],
[0,0, 35,36,37,38, 56,57,58,59,60, 0, 0, 0, 0, 0,0,0,0,0,0],
[0,0, 39,40,41,42, 61,62,63,64,65, 0, 0, 0, 0, 0,0,0,0,0,0],
[0,0, 43,44,45,46, 66,67,68,69,70, 0, 0, 0, 0, 0,0,0,0,0,0],
[0,0, 47,48,49,50, 71,72,73,74,75, 0, 0, 0, 0, 0,0,0,0,0,0],
[0,0, 0, 0, 0, 0, 51,52,53,53,55, 31,32,33,34, 0,0,0,0,0,0],
[0,0, 0, 0, 0, 0, 56,57,58,59,60, 35,36,37,38, 0,0,0,0,0,0],
[0,0, 0, 0, 0, 0, 61,62,63,64,65, 39,40,41,42, 0,0,0,0,0,0],
[0,0, 0, 0, 0, 0, 66,67,68,69,70, 43,44,45,46, 0,0,0,0,0,0],
[0,0, 0, 0, 0, 0, 71,72,73,74,75, 47,48,49,50, 0,0,0,0,0,0],
[0,0, 0, 0, 0, 0, 0,0,0,0,0,0, 31,32,33,34, 51,52,53,53,55],
[0,0, 0, 0, 0, 0, 0,0,0,0,0,0, 35,36,37,38, 56,57,58,59,60],
[0,0, 0, 0, 0, 0, 0,0,0,0,0,0, 39,40,41,42, 61,62,63,64,65],
[0,0, 0, 0, 0, 0, 0,0,0,0,0,0, 43,44,45,46, 66,67,68,69,70],
[0,0, 0, 0, 0, 0, 0,0,0,0,0,0, 47,48,49,50, 71,72,73,74,75] ]
回答2件
あなたの回答
tips
プレビュー