首页 > 解决方案 > 如何在 IlNumerics 数组中查找行

问题描述

我想根据它的值从矩阵 A 中检索一个子集。

例如,从矩阵 A(见下文),我想获得第一列值等于 9 的行预期输出:

{ 9, 12, 21 },
{ 9, 13, 23 },
{ 9, 14, 24 },
Array<double> A = new double[,] {
              { 1, 9, 20 },
              { 2, 11, 21 },
              { 9, 12, 21 },
              { 9, 13, 23 },
              { 9, 14, 24 },
              { 6, 15, 25 }
            };
            
            Array<double> test1 = A[A[0] == 9];
            Array<double> test2 = A[A == 9];

            ///Get the first column
            Array<double> D = A[full, 0];
            
            ///test 3: Get all rows where the value for the first column is 9
            Array<double> match = D.Where(e => e == 9).ToArray();

            ///test 4:Get all rows where the value for the first column is 9 from A
            Array<double> match2 = A.Where(e => e == 9).ToArray();

标签: matrixilnumerics

解决方案


如果没有测试,我想这应该可以解决问题:

Array<double> match = A[A[full, 0] == 9, full]; 

推荐阅读