Inner

2つの行列の内積。

matrix matrix::Inner(
  const matrix&  b      // 2番目の行列
  );

パラメータ

b

[in] 行列

戻り値

行列

注意事項

2つのベクトルの内積は、2つのベクトルvector::Dot()のドット積です。

 

次は、MQL5での2つの行列の内積の単純なアルゴリズムです。

bool MatrixInner(matrix& c, const matrix& a, const matrix& b)
 {
//--- 列の数は等しい必要がある
  if(a.Cols()!=b.Cols())
    return(false);
//--- 結果の行列のサイズは、各行列のベクトルの数に依存する
  ulong rows=a.Rows();
  ulong cols=b.Rows();
  matrix result(rows,cols);
//---
  for(ulong i=0; i<rows; i++)
    {
    vector v1=a.Row(i);
    for(ulong j=0; j<cols; j++)
       {
        vector v2=b.Row(j);
        result[i][j]=v1.Dot(v2);
       }
    }
//---
  c=result;
  return(true);
 }

 

MQL5の例

  matrix a={{0,1,2},{3,4,5}};
  matrix b={{0,1,2},{3,4,5},{6,7,8}};
  matrix c=a.Inner(b);
  Print(c);
  matrix a1={{0,1,2}};
  matrix c1=a1.Inner(b);
  Print(c1);
 
 /*
 [[5,14,23]
 [14,50,86]]
 [[5,14,23]]
 */

 

Pythonの例

import numpy as np
 
A = np.arange(6).reshape(2, 3)
B = np.arange(9).reshape(3, 3)
A1= np.arange(3)
print(np.inner(A, B))
print("");
print(np.inner(A1, B))
 
import numpy as np
 
A = np.arange(6).reshape(2, 3)
B = np.arange(9).reshape(3, 3)
A1= np.arange(3)
print(np.inner(A, B))
print("");
print(np.inner(A1, B))