简体   繁体   中英

F#: How to print a matrix?

I'm using Math.Net and trying to create a matrix with a random Gaussian distribution. Then I trying to print the matrix but can't:

Successive arguments should be separated by spaces or tupled, and arguments involving function or method applications should be parenthesized

What I'm doing wrong? Taking a look at examples is misleading me much more.

  printfn "%s" (DenseMatrix.random<float> 1000 50 (Normal(1.0, 100.0))).ToString()

When the error message says "arguments involving function or method applications should be parenthesized", what that means is that this:

printfn "%s" foo.ToString()

needs to be written as:

printfn "%s" (foo.ToString())

So put an extra set of parentheses around your DenseMatrix value and it should work:

printfn "%s" ((DenseMatrix.random<float> 1000 50 (Normal(1.0, 100.0))).ToString())

The reason for this language design choice gets into advanced topics like currying which you probably don't care about right now, so I'll spare you the long explanation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM