为什么 Eigen MatrixXd::transpose() 进行根本不是转置的排列?

Why Eigen MatrixXd::transpose() does permutation that is not transposition at all?

我正在尝试使用 Eigen 转置这个 4x5 矩阵:

|m00, m01, m02, m03|   |0.00000, 0.33333, 0.66667, 1.00000|
|m10, m11, m12, m13|   |0.25000, 0.41667, 0.71200, 1.03078|
|m20, m21, m22, m23| = |0.50000, 0.60093, 0.83333, 1.11803|
|m30, m31, m32, m33|   |0.75000, 0.82074, 1.00347, 1.25000|
|m40, m41, m42, m43|   |1.00000, 1.05409, 1.20185, 1.41421|

我很确定结果一定是 5x4 矩阵:

|m00, m10, m20, m30, m40|   |0.00000, 0.25000, 0.50000, 0.75000, 1.00000|
|m01, m11, m21, m31, m41| = |0.33333, 0.41667, 0.60093, 0.82074, 1.05409|
|m02, m12, m22, m32, m42|   |0.66667, 0.71200, 0.83333, 1.00347, 1.20185|
|m03, m13, m23, m33, m43|   |1.00000, 1.03078, 1.11803, 1.25000, 1.41421|

但是 MatrixXd::transpose() 实际上结果是这样的:

|m00, m11, m22, m33, m01|   |0.00000, 0.41667, 0.83333, 1.25000, 0.33333|
|m12, m43, m03, m02, m13| = |0.71200, 1.11803, 1.00000, 0.66667, 1.03078|
|m30, m41, m40, m20, m31|   |0.75000, 1.05409, 1.00000, 0.50000, 0.82074|
|m42, m10, m21, m32, m43|   |1.20185, 0.25000, 0.60093, 1.00347, 1.41421|

我不确定这是哪种排列。也不是为什么它在 Eigen 中被称为转置。希望有人能给我解开这个谜。

哦,神秘代码是:

MatrixXd m_weight;
MatrixXd m_weight_T;

// ...

m_weight_T = m_weight.transpose();

请注意,我使用的是 MSVS Community 2019。Eigen 是从 Github 中按原样获取的。我没有执行任何类型的“安装”,只是设置了包含路径。

下面的代码运行良好。

#include <iostream>
#include <Eigen/Core>


void main() {
    Eigen::MatrixXd m_weight(5, 4);

    m_weight(0, 0) = 0;
    m_weight(0, 1) = 0.33333;
    m_weight(0, 2) = 0.66667;
    m_weight(0, 3) = 1.00000;

    m_weight(1, 0) = 0.25000;
    m_weight(1, 1) = 0.41667;
    m_weight(1, 2) = 0.71200;
    m_weight(1, 3) = 1.03078;

    m_weight(2, 0) = 0.50000;
    m_weight(2, 1) = 0.60093;
    m_weight(2, 2) = 0.83333;
    m_weight(2, 3) = 1.11803;

    m_weight(3, 0) = 0.75000;
    m_weight(3, 1) = 0.82074;
    m_weight(3, 2) = 1.00347;
    m_weight(3, 3) = 1.25000;

    m_weight(4, 0) = 1.00000;
    m_weight(4, 1) = 1.05409;
    m_weight(4, 2) = 1.20185;
    m_weight(4, 3) = 1.41421;

    auto m_weight_T = m_weight.transpose();
    std::cout << "org===\n";
    std::cout << m_weight;

    std::cout << "\n";
    std::cout << "res===\n";
    std::cout << m_weight_T;
}