类型转换错误,c#
我正在使用C#中的高级矩阵库。网@ 库css文件类似于类型转换错误,c#,c#,C#,我正在使用C#中的高级矩阵库。网@ 库css文件类似于 using System; namespace MatrixLibrary { public class Matrix { private double[,] in_Mat; public Matrix(int noRows, int noCols) { this.in_Mat = new double[noRows, noCols]; }
using System;
namespace MatrixLibrary
{
public class Matrix
{
private double[,] in_Mat;
public Matrix(int noRows, int noCols)
{
this.in_Mat = new double[noRows, noCols];
}
public Matrix(double [,] Mat)
{
this.in_Mat = (double[,])Mat.Clone();
}
public static double[,] Identity(int n)
{
double[,] temp = new double[n,n];
for (int i=0; i<n;i++) temp[i,i] = 1;
return temp;
}
public static double[,] ScalarDivide(double Value, double[,] Mat)
{
int i, j, Rows, Cols;
double[,] sol;
try {Find_R_C(Mat, out Rows, out Cols);}
catch{throw new MatrixNullException();}
sol = new double[Rows+1, Cols+1];
for (i = 0; i<=Rows;i++)
for (j = 0; j<=Cols;j++)
sol[i, j] = Mat[i, j] / Value;
return sol;
}
}}
无法将typedouble[,]隐式转换为矩阵
但是
矩阵B=新矩阵(4,4);
随机rnd=新随机();
对于(int i=0;i
它可以工作,我可以有一个矩阵。请引导我
关于,函数返回一个2D数组“double[,]”,您试图将其分配给一个“矩阵”。没有一个隐式转换可以做到这一点。矩阵是否有接受“double[,]”的构造函数?也许你可以用这个
编辑:您可能还会发现,不同的矩阵库比从CodeProject中提取的矩阵库更适合您。Math.NET Numerics是我使用过的一个很好的开源软件:您需要隐式转换
public static implicit operator Matrix(double[,] m)
{
// code to convert
}
阅读错误消息 您有一个返回
double[,]
的方法,您试图将引用存储在矩阵的变量中。从多维双精度数组到矩阵没有隐式转换
要使用该方法,您可以编写
double[,] id_max = MatrixLibrary.Maxtrix.Identify(6);
如果确实需要将其存储为矩阵
,则需要定义相应的转换来执行此操作。返回双精度[,],但分配给它的变量为矩阵类型。如果没有更多的代码,很难说,但您可能希望返回一个用双数组填充的矩阵类型。
public static implicit operator Matrix(double[,] m)
{
// code to convert
}
double[,] id_max = MatrixLibrary.Maxtrix.Identify(6);