in

.NET Opensource

Community for opensource projects by Christoph Rüegg

Vector does not have ArrayMap method?

Last post 05-23-2008 13:10 by Christo. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 05-23-2008 13:10

    Vector does not have ArrayMap method?

    Matrix has got the ArrayMap method, but vector does not.

             /// <summary>
            /// In place element-by-element mapping of an arbitrary function, <c>A[i] = mapping(A[i])</c>.
            /// </summary>
            /// <seealso cref="ArrayMap(IVector, Converter&lt;double, double&gt;)"/>
            public
            void
            ArrayMap(
                Converter<double, double> mapping
                )
            {
                for(int i = 0; i < _data.Length; i++)
                {

                   _data[i] = mapping(_data[i]);
                }
            }

            /// <summary>
            /// Element-by-element mapping of an arbitrary function, <c>result[i] = mapping(M[i])</c>.
            /// </summary>
            /// <seealso cref="ArrayMap(Converter&lt;double, double&gt;)"/>
            public static
            Vector
            ArrayMap(
                IVector v,
                Converter<double, double> mapping
                )
            {
                double[ newData = new double[v.Length];
                for(int i = 0; i < v.Length; i++)
                {
                        newData[i] = mapping(v[i]);
                }

                return new Vector(newData);
            }


Page 1 of 1 (1 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems