本文整理汇总了C#中System.Double.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# Double.GetLength方法的具体用法?C# Double.GetLength怎么用?C# Double.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Double
的用法示例。
在下文中一共展示了Double.GetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveMatrix
private Boolean SaveMatrix(String fileName, Double[,] matrix)
{
try
{
StreamWriter sw = File.CreateText(fileName);
for (Int32 y = 0; y < matrix.GetLength(1); y++)
{
for (Int32 x = 0; x < matrix.GetLength(0); x++)
{
sw.Write(matrix[x, y].ToString(System.Globalization.CultureInfo.InvariantCulture));
sw.Write(" ");
}
sw.Write(Environment.NewLine);
}
sw.Close();
}
catch
{
MessageBox.Show("Error while saving the matrix to a file! Please check the path!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
return true;
}
示例2: Output
static void Output(Double[,] a)
{
for (Int32 i = 0; i < a.GetLength(0); i++)
{
for (Int32 j = 0; j < a.GetLength(1); j++)
{
Console.Write(a[i, j].ToString() + ",");
}
Console.WriteLine();
}
}
示例3: matrix
public static Term[,] matrix(Double[,] m)
{
int rows = m.GetLength(0);
int cols = m.GetLength(1);
Term[,] r = new Term[rows, cols];
for (int row = 0; row < rows; row++)
for (int col = 0; col < cols; col++)
r[row, col] = m[row, col];
return r;
}
示例4: XLMatrix
public XLMatrix(Double[,] arr)
:this(arr.GetLength(0), arr.GetLength(1))
{
var roCount = arr.GetLength(0);
var coCount = arr.GetLength(1);
for (int ro = 0; ro < roCount; ro++)
{
for (int co = 0; co < coCount; co++)
{
mat[ro, co] = arr[ro, co];
}
}
}
示例5: Main
public static void Main()
{
// define cost matrix
Double INF = Double.PositiveInfinity;
/* Double[,] costMatrix = new Double[,]
{
{ INF, 2.0, 4.0, 22.0, 2.0, INF},
{ 2.0, INF, 8.0, 15.0, 13.0, 10.0},
{ 4.0, 8.0, INF, 5.0, 2.0, INF},
{22.0, 15.0, 5.0, INF, 11.0, 12.0},
{ 2.0, 13.0, 2.0, 11.0, INF, 14.0},
{ INF, 10.0, INF, 12.0, 14.0, INF},
};
*/
Double[,] costMatrix = new Double[,]
{
{ INF, 2.0, INF, INF, 7.0},
{ 2.0, INF, 1.0, 3.0, INF},
{ INF, 1.0, INF, 1.0, 5.0},
{ INF, 3.0, 1.0, INF, INF},
{ 7.0, INF, 5.0, INF, INF},
};
costMatrix = new Double[,]
{
{ INF, 20.0, INF, 70.0},
{ 20.0, INF, 40.0, INF},
{ INF, 40.0, INF,50.0},
{ 70.0, INF, 50.0,INF},
};
// create prototype chromosome
PermutationChromosome prototype = new PermutationChromosome(0, costMatrix.GetLength(0) - 1);
// set prototype's parameters
prototype.CrossOverStrategy = new PermutationChromosome.CycleCrossOverStrategy();
prototype.RandomGenerator = new ThreadSafeRandomGenerator();
prototype.MutationStrategy = new PermutationChromosome.InsertMutationStrategy();
prototype.Fitness = new TSPFitness(costMatrix);
// stop condition, keep reference for selecting the leader
NoChangeStopCondion stopCondition = new NoChangeStopCondion(10);
// create population
DefaultPopulation population = new DefaultPopulation(prototype, 40);
// set population's parameters
population.SelectionStrategy
= new StochasticUniversalSamplingStrategy(new FixedSizeStrategy(40), new ThreadSafeRandomGenerator());
population.RandomGenerator = new ThreadSafeRandomGenerator();
population.StopCondition = stopCondition;
// perform util the stop condition returns false
while (population.NextGeneration())
;
// print the result
System.Console.WriteLine("Best fitness: " + (1.0 / stopCondition.Leader.Evaluate()));
System.Console.WriteLine(stopCondition.Leader.ToString());
System.Console.ReadKey();
}
示例6: BellmanFord
/* Takes a graph as input an adjacency matrix (see top for details) and a starting node */
public BellmanFord(Double[,] G,List<Edge> edge, int s)
{
int u, v;
/* Check graph format and that the graph actually contains something */
if (G.GetLength(0) < 1 || G.GetLength(0) != G.GetLength(1))
{
throw new ArgumentException("Graph error, wrong format or no nodes to compute");
}
int len = G.GetLength(0);
/* foreach(Vertex v in vertices)
{
if (v.ident == s) v.dist = 0;
else {v.dist = int.MaxValue; v.pre = null;}
} */
Initialize(s, len);
// for (i = 1; i <= sizeof(vertices) - 1; i++);
while (queue > 0)
{
queue = queue - 1;
/* Find the nodes that u connects to and perform relax */
foreach (Edge uv in edge)
{ u = uv.from;
v = uv.to;
/* Edge exists, relax the edge */
if (dist[u] + G[u, v] < dist[v])
{
dist[v] = dist[u] + G[u, v];
path[v] = u;
}
}
}
/* Checks for edges with negative weight */
foreach (Edge vu in edge)
{
u = vu.from;
v = vu.to;
if (G[u,v] < 0) throw new ArgumentException("Graph contains negative edge(s)");
// if (dist[u] + G[u, v] < dist[v]) throw new ArgumentException("Graph contains negative edge(s)");
}
}
示例7: printMatrix
public static string printMatrix(Double[,] matrix)
{
int rowLength = matrix.GetLength(0);
int colLength = matrix.GetLength(1);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < rowLength; i++) {
for (int j = 0; j < colLength; j++) {
Console.Write(string.Format("{0} ", matrix[i, j]));
builder.Append(string.Format("{0} ", matrix[i, j]));
}
Console.Write(Environment.NewLine + Environment.NewLine);
builder.Append(Environment.NewLine + Environment.NewLine);
}
builder.Append("\n\n");
return builder.ToString();
}
示例8: WriteAccuracy
private void WriteAccuracy(Double[,] result)
{
var p_size = result.GetLength(0);
var d_size = result.GetLength(1);
using (var writer = new StreamWriter("../Accuracy.cs"))
{
writer.WriteLine("namespace CloudBall.Engines.Toothless");
writer.WriteLine("{");
writer.WriteLine(" public partial class Statistics");
writer.WriteLine(" {");
writer.WriteLine(" private static readonly float[,] Accuracy = new float[,]{");
for (var p = 0; p < p_size; p++)
{
writer.Write("{{ {0:0.000}f /* {1:00.0}° */", result[p, 0], ToAngle(result[p, 0]));
for (var d = 1; d < d_size; d++)
{
writer.Write(", {0:0.000}f /* {1:00.0}° */", result[p, d], ToAngle(result[p, d]));
}
writer.WriteLine(" },");
}
writer.WriteLine("};}}");
}
}
示例9: PrintArrayToFile
/// <summary>
/// Prints the provided multi-dimentional array to a csv file with the given filename
/// </summary>
/// <param name='data'>
/// Data.
/// </param>
/// <param name='fileName'>
/// File name.
/// </param>
public static void PrintArrayToFile(Double[][] data, String fileName)
{
using (StreamWriter stream = File.CreateText(fileName))
{
for (Int32 x = 0; x < data.GetLength(0); x++)
{
for (Int32 y = 0; y < data[x].GetLength(0); y++)
{
if (y + 1 < data[x].GetLength(0)) stream.Write(data[x][y] + ",");
else stream.Write(data[x][y]);
}
stream.WriteLine("");
}
}
}
示例10: PrintArrayToString
public static String PrintArrayToString(Double[][] data)
{
StringBuilder theString = new StringBuilder();
for (Int32 x = 0; x < data.GetLength(0); x++)
{
for (Int32 y = 0; y < data[x].GetLength(0); y++)
{
if (y + 1 < data[x].GetLength(0)) theString.Append(data[x][y] + ",");
else theString.Append(data[x][y]);
}
theString.AppendLine();
}
return theString.ToString();
}
示例11: IsEqual
public static bool IsEqual(this Int16[][] a, Double[][] b, Double atol = 0, Double rtol = 0)
{
if (a == null && b == null)
return true;
if (a == null ^ b == null)
return false;
int[] la = a.GetLength(true);
int[] lb = b.GetLength(true);
if (la.Length != lb.Length)
return false;
for (int i = 0; i < la.Length; i++)
if (la[i] != lb[i])
return false;
if (rtol > 0)
{
for (int i = 0; i < a.Length; i++)
for (int j = 0; j < a[i].Length; j++)
{
var A = a[i][j];
var B = b[i][j];
if (A == B)
continue;
if (Double.IsNaN(B))
return false;
if (Double.IsInfinity(B))
return false;
var C = A;
var D = B;
var delta = Math.Abs(C - D);
if (C == 0)
{
if (delta <= rtol)
continue;
}
else if (D == 0)
{
if (delta <= rtol)
continue;
}
if (delta <= Math.Abs(C) * rtol)
continue;
return false;
}
}
else if (atol > 0)
{
for (int i = 0; i < a.Length; i++)
for (int j = 0; j < a[i].Length; j++)
{
var A = a[i][j];
var B = b[i][j];
if (A == B)
continue;
if (Double.IsNaN(B))
return false;
if (Double.IsInfinity(B))
return false;
var C = A;
var D = B;
if (Math.Abs(C - D) <= atol)
continue;
return false;
}
}
else
{
for (int i = 0; i < a.Length; i++)
for (int j = 0; j < a[i].Length; j++)
{
var A = a[i][j];
var B = b[i][j];
if (Double.IsNaN(B))
return false;
if (Double.IsInfinity(B))
return false;
if (A != B)
return false;
}
}
return true;
}
示例12: Map3D
public static void Map3D(MappingMode mappingMode, Double[, ,] array, ImplicitModuleBase module, MappingRanges ranges)
{
var width = array.GetLength(0);
var height = array.GetLength(1);
var depth = array.GetLength(2);
for (var x = 0; x < width; ++x)
{
for (var y = 0; y < height; ++y)
{
for (var z = 0; z < depth; ++z)
{
var p = x / (Double)width;
var q = y / (Double)height;
var r = z / (Double)depth;
Double nx;
Double ny;
Double nz;
Double nw;
Double nu;
Double dx;
Double dy;
Double dz;
var val = 0.0;
switch (mappingMode)
{
case MappingMode.SeamlessNone:
dx = ranges.MapX1 - ranges.MapX0;
dy = ranges.MapY1 - ranges.MapY0;
dz = ranges.MapZ1 - ranges.MapZ0;
nx = ranges.MapX0 + p * dx;
ny = ranges.MapY0 + q * dy;
nz = ranges.MapZ0 + r * dz;
val = module.Get(nx, ny, nz);
break;
case MappingMode.SeamlessX:
dx = ranges.LoopX1 - ranges.LoopX0;
dy = ranges.MapY1 - ranges.MapY0;
dz = ranges.MapZ1 - ranges.MapZ0;
p = p * (ranges.MapX1 - ranges.MapX0) / (ranges.LoopX1 - ranges.LoopX0);
nx = ranges.LoopX0 + Math.Cos(p * PI2) * dx / PI2;
ny = ranges.LoopX0 + Math.Sin(p * PI2) * dx / PI2;
nz = ranges.MapY0 + q * dy;
nw = ranges.MapZ0 + depth * dz;
val = module.Get(nx, ny, nz, nw);
break;
case MappingMode.SeamlessY:
dx = ranges.MapX1 - ranges.MapX0;
dy = ranges.LoopY1 - ranges.LoopY0;
dz = ranges.MapZ1 - ranges.MapZ0;
q = q * (ranges.MapY1 - ranges.MapY0) / (ranges.LoopY1 - ranges.LoopY0);
nx = ranges.MapX0 + p * dx;
ny = ranges.LoopY0 + Math.Cos(q * PI2) * dy / PI2;
nz = ranges.LoopY0 + Math.Sin(q * PI2) * dy / PI2;
nw = ranges.MapZ0 + r * dz;
val = module.Get(nx, ny, nz, nw);
break;
case MappingMode.SeamlessZ:
dx = ranges.MapX1 - ranges.MapX0;
dy = ranges.MapY1 - ranges.MapY0;
dz = ranges.LoopZ1 - ranges.LoopZ0;
r = r * (ranges.MapZ1 - ranges.MapZ0) / (ranges.LoopZ1 - ranges.LoopZ0);
nx = ranges.MapX0 + p * dx;
ny = ranges.MapY0 + q * dy;
nz = ranges.LoopZ0 + Math.Cos(r * PI2) * dz / PI2;
nw = ranges.LoopZ0 + Math.Sin(r * PI2) * dz / PI2;
val = module.Get(nx, ny, nz, nw);
break;
case MappingMode.SeamlessXY:
dx = ranges.LoopX1 - ranges.LoopX0;
dy = ranges.LoopY1 - ranges.LoopY0;
dz = ranges.MapZ1 - ranges.MapZ0;
p = p * (ranges.MapX1 - ranges.MapX0) / (ranges.LoopX1 - ranges.LoopX0);
q = q * (ranges.MapY1 - ranges.MapY0) / (ranges.LoopY1 - ranges.LoopY0);
nx = ranges.LoopX0 + Math.Cos(p * PI2) * dx / PI2;
ny = ranges.LoopX0 + Math.Sin(p * PI2) * dx / PI2;
nz = ranges.LoopY0 + Math.Cos(q * PI2) * dy / PI2;
nw = ranges.LoopY0 + Math.Sin(q * PI2) * dy / PI2;
nu = ranges.MapZ0 + r * dz;
val = module.Get(nx, ny, nz, nw, nu, 0);
break;
case MappingMode.SeamlessXZ:
dx = ranges.LoopX1 - ranges.LoopX0;
dy = ranges.MapY1 - ranges.MapY0;
dz = ranges.LoopZ1 - ranges.LoopZ0;
p = p * (ranges.MapX1 - ranges.MapX0) / (ranges.LoopX1 - ranges.LoopX0);
r = r * (ranges.MapZ1 - ranges.MapZ0) / (ranges.LoopZ1 - ranges.LoopZ0);
nx = ranges.LoopX0 + Math.Cos(p * PI2) * dx / PI2;
ny = ranges.LoopX0 + Math.Sin(p * PI2) * dx / PI2;
nz = ranges.MapY0 + q * dy;
nw = ranges.LoopZ0 + Math.Cos(r * PI2) * dz / PI2;
nu = ranges.LoopZ0 + Math.Sin(r * PI2) * dz / PI2;
val = module.Get(nx, ny, nz, nw, nu, 0);
break;
case MappingMode.SeamlessYZ:
dx = ranges.MapX1 - ranges.MapX0;
dy = ranges.LoopY1 - ranges.LoopY0;
dz = ranges.LoopZ1 - ranges.LoopZ0;
q = q * (ranges.MapY1 - ranges.MapY0) / (ranges.LoopY1 - ranges.LoopY0);
//.........这里部分代码省略.........
示例13: StandardDeviation
public static Double StandardDeviation(Double[,] numbers, Int32 columnIndex)
{
if (numbers == null)
throw new ArgumentNullException("numbers");
Int32 length = numbers.GetLength(0);
var row = new Double[length];
for (Int32 i = 0; i < length; i++)
row[i] = numbers[i, columnIndex];
return StandardDeviation(row);
}
示例14: MatrixValue
/// <summary>
/// Constructs a new matrix based on the given two dimensional array.
/// </summary>
/// <param name="values">The values which set the dimensions and starting values of the matrix.</param>
public MatrixValue(Double[,] values)
: this(values.GetLength(0), values.GetLength(1))
{
for (var j = 0; j < _dimY; j++)
{
for (var i = 0; i < _dimX; i++)
{
if (values[j, i] != 0.0)
{
this[j + 1, i + 1] = new ScalarValue(values[j, i]);
}
}
}
}
示例15: Desnormalizar
private Double[][] Desnormalizar(Double[][] vectoresEncontrados)
{
Double[][] vectorDesnormalizado = new Double[vectoresEncontrados.GetLength(0)][];
Double[][] maxYmin = csvtoMatrix("maxYmin");
int alto = vectoresEncontrados.Length;
for (int i = 0; i < alto; i++)
{
Double[] fila = new Double[10];
for (int j = 0; j < 10; j++)
{
fila[j] = (vectoresEncontrados[i][j] * (maxYmin[0][j] - maxYmin[1][j])) + maxYmin[1][j];
}
vectorDesnormalizado[i] = fila;
}
return vectorDesnormalizado;
}