本文整理汇总了C#中Matrix.set方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.set方法的具体用法?C# Matrix.set怎么用?C# Matrix.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix.set方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: multiply
public void multiply(Matrix multipliedMatrix)
{
if (multipliedMatrix.getLength(0) != matrix.GetLength(1))
{
throw new IndexOutOfRangeException();
}
Matrix newMatrix = new Matrix(matrix.GetLength(0), multipliedMatrix.getLength(1));
for (int row = 0; row < matrix.GetLength(0); row++)
{
for (int col = 0; col < multipliedMatrix.getLength(1); col++)
{
int result = 0;
for (int multipliedRow = 0; multipliedRow < matrix.GetLength(1); multipliedRow++)
{
result += matrix[row, multipliedRow] * multipliedMatrix.get(multipliedRow, col);
}
newMatrix.set(row, col, result);
}
}
matrix = newMatrix.getMatrix();
}
示例2: Main
static void Main(string[] args)
{
Matrix M = new Matrix(10, 10);
for (int i = 0; i < M.getRowDimension(); i++)
{
for (int j = 0; j < M.getColumnDimension(); j++)
{
M.set(j, i, ((i + 1) * j));
}
}
//M.print(...);
/*double[] d = new double[25];
for (int i = 0; i < 25; i++)
{
d[i] = i + 1;
}
Matrix mat = new Matrix(d, 5);
for (int i = 0; i < mat.getColumnDimension(); i++)
{
for (int j = 0; j < mat.getRowDimension(); j++)
{
Console.Write(mat.get(j,i) + " ");
}
Console.WriteLine();
}*/
}
示例3: Main
static void Main()
{
Matrix matrix = new Matrix(4, 4);
for (int row = 0; row < matrix.getLength(0); row++)
{
for (int col = 0; col < matrix.getLength(1); col++)
{
matrix.set(row, col, randGenerator.Next(10));
}
}
Matrix secondMatrix = new Matrix(4, 4);
for (int row = 0; row < secondMatrix.getLength(0); row++)
{
for (int col = 0; col < secondMatrix.getLength(1); col++)
{
secondMatrix.set(row, col, randGenerator.Next(10));
}
}
Console.WriteLine("First: ");
Console.WriteLine(matrix.toString());
Console.WriteLine(new string('-', 20));
Console.WriteLine("Second:");
Console.WriteLine(secondMatrix.toString());
Console.WriteLine(new string('-', 20));
matrix.add(secondMatrix);
Console.WriteLine("Added: ");
Console.WriteLine(matrix.toString());
Console.WriteLine(new string('-', 20));
matrix.subtract(secondMatrix);
Console.WriteLine("Subtracted: ");
Console.WriteLine(matrix.toString());
Console.WriteLine(new string('-', 20));
matrix.multiply(secondMatrix);
Console.WriteLine("Multiplied: ");
Console.WriteLine(matrix.toString());
Console.WriteLine(new string('-', 20));
}
示例4: SetColumn
/// <summary>
/// Sets a column of Matrix m specified by the index col to the values contained in the double array vals.
/// Row dimension of Matrix m must match the length of array vals. Throws an exception if these dimensions do not match
/// </summary>
/// <param name="m"></param>
/// <param name="col"></param>
/// <param name="vals"></param>
private void SetColumn(Matrix m, int col, double[] vals)
{
if(m.getRowDimension() != vals.Length) //disallow inconsistent dimensions
throw new InconsistentDimensionException("Dimension mismatch: Array length and Matrix row dimension must be equal");
for (int i = 0; i < m.getRowDimension(); i++)
m.set(i, col, vals[i]);
}
示例5: ToMatrix
/// <summary>
/// Copies the data from a Bitmap object into a Weka Matrix for purposes of matrix manipulation.
/// Future consideration: Bitmap class's LockBits() function offers better performance for large-scale changes that SetPixel()
/// </summary>
/// <returns></returns>
public Matrix ToMatrix(Bitmap bm)
{
int height = bm.Height;
int width = bm.Width;
Matrix M = new Matrix(height, width);
Color pixelColor;
//iterate through the Bitmap, getting the colors from each pixel, convert the colors to RGB alpha value and store in a Matrix
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
pixelColor = bm.GetPixel(i, j); //get pixel color from Bitmap
M.set(i, j, pixelColor.ToArgb()); //convert to alpha RGB and store in the Matrix, M
}
}
return M;
}