예제 #1
0
        public static NDArrayGeneric <T> sin <T>(this NumPyGeneric <T> np, NDArrayGeneric <T> nd)
        {
            NDArrayGeneric <T> sinArray = new NDArrayGeneric <T>();

            sinArray.Data  = new T[nd.Size];
            sinArray.Shape = new Shape(nd.Shape.Shapes);

            for (int idx = 0; idx < nd.Size; idx++)
            {
                switch (nd[idx])
                {
                case double d:
                    sinArray[idx] = (T)(object)Math.Sin(d);
                    break;

                case float d:
                    sinArray[idx] = (T)(object)Math.Sin(d);
                    break;

                case Complex d:
                    sinArray[idx] = (T)(object)Complex.Sin(d);
                    break;
                }
            }

            return(sinArray);
        }
예제 #2
0
        public static NDArrayGeneric <T> array <T>(this NumPyGeneric <T> np, IEnumerable <T> array, int ndim = 1)
        {
            var nd = new NDArrayGeneric <T>();

            nd.Data  = array.ToArray();
            nd.Shape = new Shape(new int[] { nd.Data.Length });

            return(nd);
        }
예제 #3
0
        public static NDArrayGeneric <Byte> array <T>(this NumPyGeneric <T> np, System.Drawing.Bitmap image)
        {
            NDArrayGeneric <Byte> imageArray = new NDArrayGeneric <Byte>();

            var bmpd     = image.LockBits(new System.Drawing.Rectangle(0, 0, image.Width, image.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, image.PixelFormat);
            var dataSize = bmpd.Stride * bmpd.Height;

            imageArray.Data = new byte[dataSize];
            System.Runtime.InteropServices.Marshal.Copy(bmpd.Scan0, imageArray.Data, 0, imageArray.Data.Length);
            image.UnlockBits(bmpd);

            imageArray.Shape = new Shape(new int[] { bmpd.Height, bmpd.Width, System.Drawing.Image.GetPixelFormatSize(image.PixelFormat) / 8 });

            return(imageArray);
        }
예제 #4
0
        /// <summary>
        /// Return a new array of given shape and type, filled with ones.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="np"></param>
        /// <param name="shape"></param>
        /// <returns></returns>
        public static NDArrayGeneric <T> ones <T>(this NumPyGeneric <T> np, Shape shape)
        {
            var nd = new NDArrayGeneric <T>();

            nd.Shape = shape;

            switch (default(T))
            {
            case int data:
                nd.Data = Enumerable.Range(0, nd.Size).Select(x => (T)(object)1).ToArray();
                break;

            case double data:
                nd.Data = Enumerable.Range(0, nd.Size).Select(x => (T)(object)1.0).ToArray();
                break;
            }

            return(nd);
        }
예제 #5
0
        public static NDArrayGeneric <T> array <T>(this NumPyGeneric <T> np, T[][] data)
        {
            int size = data.Length * data[0].Length;
            var all  = new T[size];

            int idx = 0;

            for (int row = 0; row < data.Length; row++)
            {
                for (int col = 0; col < data[row].Length; col++)
                {
                    all[idx] = data[row][col];
                    idx++;
                }
            }

            var n = new NDArrayGeneric <T>();

            n.Data  = all;
            n.Shape = new Shape(new int[] { data.Length, data[0].Length });

            return(n);
        }
예제 #6
0
        public static NDArrayGeneric <NDArrayGeneric <T> > sin <T>(this NumPyGeneric <T> np, NDArrayGeneric <NDArrayGeneric <T> > nd)
        {
            var sinArray = new NDArrayGeneric <NDArrayGeneric <T> >();

            sinArray.Data  = new NDArrayGeneric <T> [nd.Size];
            sinArray.Shape = new Shape(nd.Shape.Shapes);

            for (int idx = 0; idx < nd.Size; idx++)
            {
                switch (default(T))
                {
                case double d:
                    sinArray[idx] = new NDArrayGeneric <T>
                    {
                        Data  = new T[] { (T)(object)Math.Sin(d) },
                        Shape = new Shape(1)
                    };
                    break;
                }
            }

            return(sinArray);
        }
예제 #7
0
 public static NDArrayGeneric <T> asarray <T>(this NumPyGeneric <T> np, IEnumerable <T> array, int ndim = 1)
 {
     return(np.array(array));
 }
예제 #8
0
 public static NDArrayGeneric <T> ones_like <T>(this NumPyGeneric <T> np, NDArrayGeneric <T> nd, string order = "C")
 {
     return(np.ones(new Shape(nd.Shape.Shapes)));
 }