Ejemplo n.º 1
0
        public void VStackNDArrays()
        {
            //1D
            var np = new NumPyGeneric <double>();
            var n1 = np.array(new double[] { 1, 2, 3 });
            var n2 = np.array(new double[] { 2, 3, 4 });

            var n = np.vstack(n1, n2);

            Assert.IsTrue(n.Size == (n1.Size + n2.Size));
            Assert.IsTrue(n[0, 0] == 1);
            Assert.IsTrue(n[1, 0] == 2);
            Assert.IsTrue(n[1, 2] == 4);

            //2D
            n1 = np.array(new double[][] { new double[] { 1 }, new double[] { 2 }, new double[] { 3 } });
            n2 = np.array(new double[][] { new double[] { 4 }, new double[] { 5 }, new double[] { 6 } });

            n = np.vstack(n1, n2);

            Assert.IsTrue(n.Size == (n1.Size + n2.Size));
            Assert.IsTrue(n[0, 0] == 1);
            Assert.IsTrue(n[1, 0] == 2);
            Assert.IsTrue(n[2, 0] == 3);
            Assert.IsTrue(n[3, 0] == 4);
            Assert.IsTrue(n[4, 0] == 5);
            Assert.IsTrue(n[5, 0] == 6);
        }
Ejemplo n.º 2
0
        public void HStackNDArrays()
        {
            //1D
            var np = new NumPyGeneric <double>();
            var n1 = np.array(new double[] { 1, 2, 3 });
            var n2 = np.array(new double[] { 2, 3, 4 });

            var n = np.hstack(n1, n2);

            Assert.IsTrue(n.Size == (n1.Size + n2.Size));
            Assert.IsTrue(n[0] == 1);
            Assert.IsTrue(n[1] == 2);
            Assert.IsTrue(n[3] == 2);
            Assert.IsTrue(n[5] == 4);

            //2D
            n1 = np.array(new double[][] { new double[] { 1 }, new double[] { 2 }, new double[] { 3 } });
            n2 = np.array(new double[][] { new double[] { 4 }, new double[] { 5 }, new double[] { 6 } });

            n = np.hstack(n1, n2);

            Assert.IsTrue(n.Size == (n1.Size + n2.Size));
            Assert.IsTrue(n[0, 0] == 1);
            Assert.IsTrue(n[1, 0] == 2);
            Assert.IsTrue(n[2, 0] == 3);
            Assert.IsTrue(n[0, 1] == 4);
            Assert.IsTrue(n[1, 1] == 5);
            Assert.IsTrue(n[2, 1] == 6);

            //3D
            n1 = np.arange(12).reshape(2, 3, 2);
            n2 = np.arange(12).reshape(2, 3, 2);
            n  = np.hstack(n1, n2);

            Assert.IsTrue(n.Size == (n1.Size + n2.Size));
            Assert.IsTrue(n[0, 0, 0] == 0);
            Assert.IsTrue(n[0, 1, 0] == 2);
            Assert.IsTrue(n[0, 2, 1] == 5);

            //4D
            //n1 = np.arange(24 * 10000000).ReShape(20000, 30, 20, 2);
            //n2 = np.arange(24 * 10000000).ReShape(20000, 30, 20, 2);
            //n = np.hstack(n1, n2);

            //Assert.IsTrue(n.Size == (n1.Size + n2.Size));
        }
Ejemplo n.º 3
0
        public static NDArrayGeneric <T> delete <T>(this NumPyGeneric <T> np, NDArrayGeneric <T> nd, IEnumerable <T> delete)
        {
            var nd1 = np.array(nd.Data.Where(x => !delete.Contains(x)));

            nd1.Shape = new Shape(nd1.Data.Length);

            return(nd1);
        }
Ejemplo n.º 4
0
        public void Simple1DArray()
        {
            var np = new NumPyGeneric <double>();
            var nd = np.array(new double[] { 0, 30, 45, 60, 90 }) * (Math.PI / 180);

            var nd2 = np.sin(nd);

            Assert.IsTrue(nd2[0] == 0);
            Assert.IsTrue(nd2[1] < 0.501);
            Assert.IsTrue(nd2[1] > 0.498);
            Assert.IsTrue(nd2[2] < 0.708);
            Assert.IsTrue(nd2[2] > 0.7069);
            Assert.IsTrue(nd2[3] < 0.867);
            Assert.IsTrue(nd2[3] > 0.8659);
            Assert.IsTrue(nd2[4] == 1);
        }