2

我创建了以下矩阵,并且我想确定矩阵现在具有的行/列数:

module AswanBigMatrix {
  use LinearAlgebra;

  proc main() {
    var A = Matrix(
         [0.0, 0.8, 1.1, 0.0, 2.0]
        ,[0.8, 0.0, 1.3, 1.0, 0.0]
        ,[1.1, 1.3, 0.0, 0.5, 1.7]
        ,[0.0, 1.0, 0.5, 0.0, 1.5]
        ,[2.0, 0.0, 1.7, 1.5, 0.0]
        );
    }
   writeln(A.domain);
}

这返回{0..4, 0..4}是有道理的,但我不能以A.domain[0]获取长度为例。

4

1 回答 1

3

差不多好了:

   const                D = {1..8,1..9};
   var       Matrix_A: [D] int;
   writeln( "Matrix_A[] has a .domain() of [ ",
             Matrix_A.domain.dims(),       " ], the 1st-dimension being: ",
             Matrix_A.domain.dim(1).length()
             );
   writeln( "Matrix_A[] has a  .shape() of ( ",
             Matrix_A.shape,              " ),       ",
                                               "the 1st-dimension being: ",
             Matrix_A.shape[1]
             );

输出:

Matrix_A[] has a .domain() of [ (1..8, 1..9) ], the 1st-dimension being: 8
Matrix_A[] has a  .shape() of ( (8, 9) ),       the 1st-dimension being: 8
于 2017-08-16T11:45:28.267 回答