Casting F#将obj[,]铸造为浮动[,]
我有一个Casting F#将obj[,]铸造为浮动[,],casting,f#,Casting,F#,我有一个obj[,],它的组件都是floats。我想将其转换为浮点[,]。我尝试了多种排列方式,如框,取消框,数组2d.map float,数组2d.copy,系统.Convert.ChangeType,但似乎都不起作用。如何继续?这对我来说似乎很好: let boxedArray = Array2D.init 2 2 (fun x y -> box (float (x + y))) let unboxedArray = boxedArray |> Array2D.map unbox
obj[,]
,它的组件都是float
s。我想将其转换为浮点[,]
。我尝试了多种排列方式,如框
,取消框
,数组2d.map float
,数组2d.copy
,系统.Convert.ChangeType
,但似乎都不起作用。如何继续?这对我来说似乎很好:
let boxedArray = Array2D.init 2 2 (fun x y -> box (float (x + y)))
let unboxedArray = boxedArray |> Array2D.map unbox<float>
printfn "%A" (boxedArray.GetType()) // System.Object[,]
printfn "%A" (unboxedArray.GetType()) // System.Double[,]
let boxedArray=Array2D.init 2 2(fun x y->box(float(x+y)))
让unboxedArray=boxedArray |>Array2D.map unbox
printfn“%A”(boxedArray.GetType())//System.Object[,]
printfn“%A”(unbxedarray.GetType())//System.Double[,]
这对我来说似乎很好:
let boxedArray = Array2D.init 2 2 (fun x y -> box (float (x + y)))
let unboxedArray = boxedArray |> Array2D.map unbox<float>
printfn "%A" (boxedArray.GetType()) // System.Object[,]
printfn "%A" (unboxedArray.GetType()) // System.Double[,]
let boxedArray=Array2D.init 2 2(fun x y->box(float(x+y)))
让unboxedArray=boxedArray |>Array2D.map unbox
printfn“%A”(boxedArray.GetType())//System.Object[,]
printfn“%A”(unbxedarray.GetType())//System.Double[,]
向我们展示一些您尝试过的代码,并描述它到底是如何不起作用的。是否存在编译器错误、运行时异常、意外输出或其他情况?向我们展示一些您尝试过的代码,并描述它到底是如何不起作用的。是否存在编译器错误、运行时异常、意外输出或其他问题?明白了。我试着做boxedArray |>unbox |>Array2D.map float
,得到了一个运行时系统。InvalidCastException
得到了它。我试图执行boxedArray>unbox>Array2D.map float
并获得一个运行时系统。InvalidCastException