我需要(用于快速原型设计和库集成)这样的东西(常用数组的扩展)


double[] d;
d.SetRow(1,{ 1.1 , 2.0 ,3.3});
var r = d.GetRow(1);
d = d.AppendRight(new int[]{1,2,3});
...

在任何地方都存在这样的事吗? 可能是任何人都实现了它,所以我不需要自己做我自己吗?

有帮助吗?

解决方案

这不应该太难写自己。

要非常小心的是如何将数组编辑为属性。

类似(非常粗略的未经测试的代码,但应该给你一个想法):

public class ArrayRow<T> {
    //add your own ..ctor etc

    T[,] matrix; //don't make this public see http://msdn.microsoft.com/en-us/library/k2604h5s.aspx
    public int Index { get; private set; }

    //note that this will be a copy
    public T[] GetValues() {
        T[] retval = new T[matrix.GetLength(1)];
        for ( int i = 0; i < retval.Length; i++ )
           retval[i] = matrix[Index, i];

        return retval;
    }

    public void SetValues(T[] values)
    //..and so on, you get the idea
}

然后扩展数组:

public static ArrayExtensions {

    public void SetRow<T> ( this T[,] matrix, int rowIndex, T[] values ) {
        //check rowIndex in range and array lengths match
    }

    public ArrayRow<T> GetRow<T> ( this T[,] matrix, int rowIndex ) {
        //check rowIndex in range
        return new ArrayRow<T> ( matrix, rowIndex );
    }
}

然后你可以依赖推断出的类型参数。

其他提示

查看 Math.NET 。它是一个开源数学库。你可能会找到你需要的东西。

他们在页面的末尾有一个使用矩阵的示例。

Python等语言支持混合类型的列表。您可以创建IronPython脚本,然后从C#应用程序中调用它。关注此链接,了解如何从您的应用中调用IronPython脚本。

我将 Matrix Extensions C#库写入基于测试扩展的代码生成设计。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top