本文整理汇总了C#中System.Double.Select方法的典型用法代码示例。如果您正苦于以下问题:C# Double.Select方法的具体用法?C# Double.Select怎么用?C# Double.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Double
的用法示例。
在下文中一共展示了Double.Select方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRatios
/// <summary>
/// Gets an array of coefficients that can be used to weight a numerical sequence of the specified length.
/// The value of an element in the array represents the weighting coefficient for the item at the corresponding index in the sequence.
/// </summary>
/// <param name="rateOfChange">The rate at which the ratios change.</param>
/// <param name="length">The length of the sequence for which weighting coefficients will be returned.</param>
/// <returns>An array of <paramref name="length"/> length, that contains the weighting coefficients.</returns>
/// <remarks>
/// The sum of the array's elements should always equal 1.
/// When a low value is provided for <paramref name="length"/>, the sum of the array elements is measurably smaller than 1.
/// Consequently, after all elements in the sequence have been calculated, the remainder is divided equally between all elements such that their sum approaches 1.
/// </remarks>
public Double[] GetRatios(Int32 length, Double rateOfChange = 0.5)
{
Double[] ratios = new Double[length];
Double currentAmount = 1;
for (Int32 i = 0; i < ratios.Length; i++)
{
Double currentVal = currentAmount * rateOfChange;
Double remaining = currentAmount - currentVal;
currentAmount = remaining;
ratios[i] = currentVal;
}
// As the number of buckets increases, the sum of the buckets approaches 1.
// When the number of buckets is very small, a significant portion is not represented in the output.
// To account for this, we split the remaining portion and apply it evenly among every bucket.
currentAmount /= length;
// Sometimes Resharper is a little dumb.
// ReSharper disable once RedundantAssignment
ratios = ratios.Select(bucket => bucket += currentAmount).ToArray();
return ratios;
}
示例2: CalculateNormalizeVector
private static Double[] CalculateNormalizeVector(Double[,] matrix)
{
Int32 n = matrix.GetLength(0);
Double[] notNormalizeVector = new Double[n];
for (Int32 i = 0; i < n; i++)
{
Double tmp = 1;
for (Int32 j = 0; j < n; j++)
{
tmp *= matrix[i, j];
}
notNormalizeVector[i] = Math.Pow(tmp, (Double)1/n);
}
Double sumOfVector = notNormalizeVector.Sum();
Double[] normalizeVector = notNormalizeVector.Select(v => v / sumOfVector).ToArray();
return normalizeVector;
}