先给出SimpleMatrix.cs的开头,定义总行数、总列数、所有数据(double类型)
using System;
using System.IO;
namespace NeuralDefs.Matrix
{
public class SimpleMatrix : IMatrix
{
public int Row { get; set; }
public int Column { get; set; }
public double[,] Data { get; set; }
其中用了IMatrix矩阵来组织,因为我还写了稀疏矩阵的。关于这个接口在介绍稀疏矩阵时候再写
1、首先实现简单矩阵的最基本功能——赋值和输出
我经常用csv格式的文件,用自然方式存储和查看矩阵
public SimpleMatrix(int row, int col)
{
// init matrix
Row = row;
Column = col;
Data = new double[row, col];
for (var i = 0; i < row; i++)
{
for (var j = 0; j < col; j++)
{
Data[i, j] = 0;
}
}
}
public SimpleMatrix(string fileName)
{
//var splitUnit = '\t';
var splitUnit = ',';
// count columns
var srCol = new StreamReader(fileName);
var firstLine = srCol.ReadLine();
if (firstLine != null)
{
var firstArray = firs