c++ - 如何将矩阵映射到某个整数值?

标签 c++ dictionary matrix

比如我要映射

       1  2  3
       3  4  1 -> 0
       1  1  1 

       1  2  3
       1  1  2 -> 1
       1  1  1 

等等。是否可以使用 std::map ?

编辑:我的意思是问我是否有一个二维数组或一维 vector 数组,如何将它与一些整数值映射。

最佳答案

使用 std::arraystd::array 如下:

std::map< int, std::array<std::array< int , 3>, 3> > m = 
{ {0, {{ { 1,2,3},
         { 3,4,1},
         { 1,1,1} 
      }} 
  }, 
  {1, {{ 
         { 1,2,3},
         { 1,1,2},
         { 1,1,1} 
      }} 
  } 
};

如果编译时行和列未知,您可以使用 std::vectorstd::vector

std::map< int, std::vector<std::vector< int > > > m;

对于相反的矩阵到整数的映射,您只需颠倒顺序即可:

std::map< std::array<std::array< int , 3>, 3>, int  > m_opp =
{ { {{ { 1,2,3},
         { 3,4,1},
         { 1,1,1} 
      }}, 
    0 
  }, 
  { {{ 
         { 1,2,3},
         { 1,1,2},
         { 1,1,1} 
      }}, 
    1 
  } 
};

std::map< std::vector<std::vector< int > >, int > m_opp;

关于c++ - 如何将矩阵映射到某个整数值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42743726/

相关文章:

c - 在 C 中获取二维数组的输入

python - 以正确的顺序从数组构建 block 矩阵

c++ - 在 C++ 中是否有强大的保证交换的工具

c++ - 了解 C++11 中的 <system_error> 工具

c++ - std::vector 是否使用 push_back 复制对象?

python - 根据定义的顺序获取Python字典中字典值最小的键列表

c++ - 在 c++ std 库中,分配给索引 -1 处的映射元素

r - 当矩阵的维数未知时,如何设置唯一的行名和列名?

c++ - RegSetValueEx 函数写乱码

python - 在 python 中反转 dict 和访问它的值的正确方法是什么?