[英]Eigen Matrix Vector Division
我正在嘗試在Eigen中實現一個Normalizer。
它試圖實現的功能如下:
Xnorm = (X - np.mean(X, axis=0))/(np.std(X, axis=0))
(等效numpy)
在主標准化步驟中,我有如下函數:
typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
matrix_eig;
typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::RowMajor> vector_eig;
matrix_eig Normalizer::Transform(const matrix_eig &X) {
// mean_ and std_ are vector_eig types
matrix_eig centered = X.rowwise() - mean_.transpose();
// Below line doesnt work since '/' is not allowed for matrices
return centered.rowwise()/std_;
}
我的問題是我究竟如何做像centered.rowwise().array()
?
問題是:
我究竟該怎樣做像
centered.rowwise().array()
答案很簡單:
centered.array().rowwise()
因此,您應該將該部門寫為:
return centered.array().rowwise() / std_.array();
順便說一下, vector_eig
的定義也有錯誤。 如果你想要一個行向量,那么它是:
typedef Eigen::Matrix<float, 1, Eigen::Dynamic> vector_eig;
或者干脆:
typedef Eigen::RowVectorXf vector_eig;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.