예제 #1
0
        /// <summary>
        /// Return coordinate matrices from coordinate vectors.
        /// Make N-D coordinate arrays for vectorized evaluations of
        /// N-D scalar/vector fields over N-D grids, given
        /// one-dimensional coordinate arrays x1, x2,..., xn.
        /// .. versionchanged:: 1.9
        /// 1-D and 0-D cases are allowed.
        /// </summary>
        /// <param name="x1"> 1-D arrays representing the coordinates of a grid</param>
        /// /// <param name="x2"> 1-D arrays representing the coordinates of a grid</param>
        /// <returns></returns>
        public static (NDArray, NDArray) meshgrid(NDArray x1, NDArray x2, Kwargs kwargs = null)
        {
            if (kwargs == null)
            {
                kwargs = new Kwargs();
            }

            int ndim   = 2;
            var s0     = (1, 1);
            var output = new NDArray[] { x1.reshape(x1.size, 1), x2.reshape(1, x2.size) };

            if (kwargs.indexing == "xy" && ndim > 1)
            {
                // Switch first and second axis
                output = new NDArray[] { x1.reshape(1, x1.size), x2.reshape(x2.size, 1) };
            }

            if (!kwargs.sparse)
            {
                // Return the full N-D matrix(not only the 1 - D vector)
                output = np.broadcast_arrays(output[0], output[1], true);
            }

            if (kwargs.copy)
            {
            }

            return(output[0], output[1]);
        }
예제 #2
0
        public void MeshgridTest()
        {
            NDArray X = np.array(0, 1, 2);

            NDArray y = np.array(0, 1);

            Kwargs kw = new Kwargs();

            kw.indexing = "xy";
            kw.sparse   = false;

            var(xx, yy) = np.meshgrid(X, y, kw);

            // Assert.IsTrue(xx, np.array(new int[,] { { 0,1,2}, { 0,1,2} }));
            // Assert.IsTrue(yy, np.array(new int[,] { { 0, 0, 0 }, { 1, 1, 1 } }));
        }