簡體   English   中英

打字矩陣<float>使用 Plotly 和 F# .Net Interactive 在 F 中 seq&lt;&#39;a * &#39;b&gt;

[英]Typcasting Matrix<float> to seq<'a * 'b> in F with Plotly and F# .Net Interactive

#r "nuget: MathNet.Numerics"
#r "nuget: MathNet.Numerics.FSharp"
#r "nuget: Plotly.NET, 2.0.0"
#r "nuget: Plotly.NET.Interactive, 2.0.0"

open Plotly.NET 
open MathNet.Numerics
open MathNet.Numerics.LinearAlgebra

let matrix1 =   matrix [[1.0; 2.0]; [5.0; 6.0]]
let matrix2 =  matrix [[3.0; 3.0]; [7.0; 8.0]]
let matrix12 = matrix1 * matrix2

let myFirstChart = Chart.Point(matrix12) //TYPE CAST ERROR
let myFirstStyledChart =
    Chart.Point(xData,yData)
    |> Chart.withTitle "Hello world!"
    |> Chart.withXAxisStyle ("xAxis")
    |> Chart.withYAxisStyle ("yAxis")
    |> Chart.show

我得到錯誤

Error: input.fsx (9,32)-(9,40) typecheck error The type 'Matrix<float>' is not compatible with the type 'seq<'a * 'b>'
input.fsx (9,32)-(9,40) typecheck error Type constraint mismatch. The type 
    'Matrix<float>'    
is not compatible with type
    'seq<'a * 'b>'  

是否有一些緊湊的方法可以在 F# 中將類型從 Matrix 轉換為 seq<> 而無需進行大轉換功能。 我只是在尋找快速顯示向量和矩陣的方法。

它不需要是一個復雜的函數,但您需要某種方法將矩陣轉換為 x 和 y 數據將在您的繪圖上顯示的內容。 例如:

let x = matrix12.ToArray()

let plottable = 
    seq {
        for i in 0..(Array2D.length1 x - 1) do
            for j in 0..(Array2D.length2 x - 1) do
                yield (i * j), x.[i, j]

    }
let myFirstChart = Chart.Point(plottable)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM