Beispiel #1
0
        internal static ndarray PrependOnes(ndarray arr, int nd, int ndmin)
        {
            npy_intp[] newdims    = new npy_intp[ndmin];
            npy_intp[] newstrides = new npy_intp[ndmin];
            int        num        = ndmin - nd;

            // Set the first num dims and strides for the 1's
            for (int i = 0; i < num; i++)
            {
                newdims[i]    = (npy_intp)1;
                newstrides[i] = (npy_intp)arr.ItemSize;
            }
            // Copy in the rest of dims and strides
            for (int i = num; i < ndmin; i++)
            {
                int k = i - num;
                newdims[i]    = (npy_intp)arr.Dim(k);
                newstrides[i] = (npy_intp)arr.Stride(k);
            }

            return(NpyCoreApi.NewView(arr.Dtype, ndmin, newdims, newstrides, arr, 0, false));
        }