当前位置: 首页>>代码示例>>C#>>正文


C# ILArray.Reshape方法代码示例

本文整理汇总了C#中ILArray.Reshape方法的典型用法代码示例。如果您正苦于以下问题:C# ILArray.Reshape方法的具体用法?C# ILArray.Reshape怎么用?C# ILArray.Reshape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILArray的用法示例。


在下文中一共展示了ILArray.Reshape方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: meshgrid

        /// <summary>
        /// Create three 3D arrays for the valuation and visualization of functions of three variables 
        /// </summary>
        /// <param name="x">Vector of x values</param>
        /// <param name="y">Vector of y values</param>
        /// <param name="z">Vector of z values</param>
        /// <returns>A List of three arrays, the rows of the first comprising the x vector values and the columns of the second comprising the y vector values</returns>
        /// <remarks></remarks>
        public static List<ILArray<double>> meshgrid(ILArray<double> x, ILArray<double> y, ILArray<double> z)
        {
            if (!x.IsVector || !y.IsVector || !z.IsVector)
            {
                throw new ILArgumentException("meshgrid: inputs must be vectors");
            }
            int xLength = x.Length;
            int yLength = y.Length;
            int zLength = z.Length;
            //ILDimension dimRet = new ILDimension(xLength, yLength, zLength);
            //double[] retArrX = ILMemoryPool.Pool.New<double>(dimRet.NumberOfElements);
            //double[] retArrY = ILMemoryPool.Pool.New<double>(dimRet.NumberOfElements);
            //double[] retArrZ = ILMemoryPool.Pool.New<double>(dimRet.NumberOfElements);
            //unsafe
            //{
            //    fixed (double* pRetArrX = retArrX)
            //    fixed (double* pRetArrY = retArrY)
            //    fixed (double* pRetArrZ = retArrZ)
            //    fixed (double* pX = x.m_data)
            //    fixed (double* pY = y.m_data)
            //    fixed (double* pZ = z.m_data)
            //    {
            //        double* pRetArrayX = pRetArrX;
            //        double* pRetArrayY = pRetArrY;
            //        double* pRetArrayZ = pRetArrZ;
            //        double* pArrayX;
            //        double* pArrayY;
            //        double* pArrayZ = pZ;
            //        double* pXEnd = pX + xLength;
            //        double* pYEnd = pY + yLength;
            //        double* pZEnd = pZ + zLength;
            //        while (pArrayZ < pZEnd)
            //        {
            //            pArrayY = pY;
            //            while (pArrayY < pYEnd)
            //            {
            //                pArrayX = pX;
            //                while (pArrayX < pXEnd)
            //                {
            //                    *pRetArrayX = *pArrayX;
            //                    *pRetArrayY = *pArrayY;
            //                    *pRetArrayZ = *pArrayZ;
            //                    pArrayX++;
            //                    pRetArrayX++;
            //                    pRetArrayY++;
            //                    pRetArrayZ++;
            //                }
            //                pArrayY++;
            //            }
            //            pArrayZ++;
            //        }

            //    }
            //}

            List<ILArray<double>> retList = new List<ILArray<double>>();
            if (!x.IsRowVector) x.Reshape(1,x.Length); 
            if (!y.IsColumnVector) y.Reshape(y.Length,1);  
            z = z[":"].Reshape(1,1,z.Dimensions.NumberOfElements); 

            retList.Add(repmat(x,yLength,1,zLength));
            retList.Add(repmat(y,1,xLength,zLength));
            retList.Add(repmat(z,yLength,xLength,1));
            return retList;
        }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:73,代码来源:meshgrid.cs

示例2: CreateVertices

            internal static ILArray<double> CreateVertices(ILBaseArray dataInput 
                                            ,out ILArray<double> indices
                                            ,double beta, double scaling
                                            , ILColormap colormap) {
                // each arrow needs 4 vertices (indexed rendering)
                ILArray<double> data = todouble(dataInput);
                int numRows = data.Dimensions[0];
                int numCols = data.Dimensions[1];
                ILArray<double> ret = new ILArray<double>(4, numCols * numRows, 2);
                // prepare indices
                indices = repmat(new ILArray<double>(new double[] { 0, 2, 1, 2, 3, 2 }, 6, 1), 1, numCols * numRows);
                indices = indices + repmat(counter(0.0, 4.0, 1, numCols * numRows), 6, 1);
                indices = indices.Reshape(2, numRows * numCols * 3);
                // normalize incoming data to length 1.0 
                ILArray<double> l = sqrt(sum(data * data, 2));
                double maxL = (double)max(maxall(l),MachineParameterDouble.eps);
                l = (l / maxL)[":"].T * scaling;
                ILArray<double> alpha = atan2(data[":;:;1"], data[":;:;0"]);
                alpha = alpha[":"].T;
                ILArray<double> x = data[":;:;0"][":"].T * scaling;
                ILArray<double> y = data[":;:;1"][":"].T * scaling;
                ILArray<double> xO = repmat(linspace(1, numCols, numCols), numRows, 1)[":"].T;
                ILArray<double> yO = repmat(linspace(numRows, 1, numRows).T, 1, numCols)[":"].T;
                ret["0;:;0"] = xO - x;
                ret["1;:;0"] = xO + x - l / 2 * cos(alpha + beta);
                ret["2;:;0"] = xO + x;
                ret["3;:;0"] = xO + x - l / 2 * cos(alpha - beta);

                ret["0;:;1"] = yO - y;
                ret["1;:;1"] = yO + y - l / 2 * sin(alpha + beta);
                ret["2;:;1"] = yO + y;
                ret["3;:;1"] = yO + y - l / 2 * sin(alpha - beta);

                ret["0;0;2"] = 0.0;
                // prepare colors 
                ret[":;:;3:5"] = todouble(
                    repmat(colormap.Map
                            (tosingle(l) * colormap.Length).Reshape(1, l.Length, 3) * 255, 4, 1, 1));
                return ret.Reshape(4 * numRows * numCols, 6).T;
            }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:40,代码来源:ILVectorField2D.cs


注:本文中的ILArray.Reshape方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。