/// <summary> /// Calculates the variance of the elements along the specified axis. /// </summary> /// <param name="axis">The axis to operate along.</param> /// <param name="source">The NdArray containing the source values.</param> /// <param name="ddof">The delta degrees of freedom.</param> /// <returns>A new NdArray containing the result of this operation.</returns> public static NdArray <T> VarAxis(int axis, NdArray <T> source, T deltaDegreeOfFreedom) { var sp = ScalarPrimitivesRegistry.For <T, int>(); var spc = ScalarPrimitivesRegistry.For <int, T>(); var mean = NdArray <T> .InsertAxis(axis, NdArray <T> .MeanAxis(axis, source)); var v = source - mean; var n = sp.Convert(source.Shape[axis] - spc.Convert(deltaDegreeOfFreedom)); return(SumAxis(axis, (v * v) / NdArray <T> .ScalarLike(source, n))); }