Exemplo n.º 1
0
        public NumSharp.Generic.NDArray <T> MakeGeneric <T>() where T : struct
        {
            var genericArray = new NumSharp.Generic.NDArray <T>(this.Storage.Shape);

            genericArray.Storage.SetData(this.Storage.GetData <T>());

            return(genericArray);
        }
Exemplo n.º 2
0
        public NDArray this[NumSharp.Generic.NDArray <bool> booleanArray]
        {
            get
            {
                if (!Enumerable.SequenceEqual(this.shape, booleanArray.shape))
                {
                    throw new IncorrectShapeException();
                }

                List <object> selectedList = new List <object>();

                bool[] boolDotNetArray = booleanArray.Storage.GetData() as bool[];

                int elementsAmount = booleanArray.size;

                Array data = this.Storage.GetData();

                for (int idx = 0; idx < elementsAmount; idx++)
                {
                    if (boolDotNetArray[idx])
                    {
                        int[] indexes = booleanArray.Storage.Shape.GetDimIndexOutShape(idx);
                        selectedList.Add(data.GetValue(this.Storage.Shape.GetIndexInShape(indexes)));
                    }
                }

                NDArray selected = new NDArray(this.dtype, selectedList.Count);
                selected.Storage.SetData(selectedList.ToArray());

                return(selected);
            }
            set
            {
                if (!Enumerable.SequenceEqual(this.shape, booleanArray.shape))
                {
                    throw new IncorrectShapeException();
                }

                object scalarObj = value.Storage.GetData().GetValue(0);

                bool[] boolDotNetArray = booleanArray.Storage.GetData() as bool[];

                int   elementsAmount = booleanArray.size;
                Array data           = this.Storage.GetData();

                for (int idx = 0; idx < elementsAmount; idx++)
                {
                    if (boolDotNetArray[idx])
                    {
                        int[] indexes = booleanArray.Storage.Shape.GetDimIndexOutShape(idx);
                        data.SetValue(scalarObj, this.Storage.Shape.GetIndexInShape(indexes));
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void Compare()
        {
            NDArray A = new double[, ] {
                { 1, 2, 3 }, { 4, 5, 6 }
            };

            NumSharp.Generic.NDArray <bool> boolArr = (A < 3);

            A[A < 3] = -2;

            var a = A[A == -2 | A > 5];
        }