Reshape

データを変更せずに行列の形状を変更します。

void  Reshape(
  const ulong  rows,    // 新しい行数
  const ulong  cols      // 新しい列数
  );

パラメータ

rows

[in] 新しい行数

cols

[in] 新しい列数

注意事項

行列はその場で処理されます。コピーは作成されません。任意のサイズを指定できます。つまり、rows_new*cols_new!=rows_old*cols_oldです。行列のバッファが増加すると、余分な値は定義されません。

  matrix matrix_a={{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
 
  Print("matrix_a\n",matrix_a);
  matrix_a.Reshape(2,6);
  Print("Reshape(2,6)\n",matrix_a);
  matrix_a.Reshape(3,5);
  Print("Reshape(3,5)\n",matrix_a);
  matrix_a.Reshape(2,4);
  Print("Reshape(2,4)\n",matrix_a);
 
 /*
matrix_a
 [[1,2,3]
  [4,5,6]
  [7,8,9]
  [10,11,12]]
Reshape(2,6)
 [[1,2,3,4,5,6]
  [7,8,9,10,11,12]]
Reshape(3,5)
 [[1,2,3,4,5]
  [6,7,8,9,10]
  [11,12,0,3,0]]
Reshape(2,4)
 [[1,2,3,4]
  [5,6,7,8]]
 */