示例#1
0
        public static NDArray astype(NDArray x, DType dtype)
        {
            if (x.dtype == dtype)
            {
                return(x);
            }

            var array = (Array)x.data.Clone();

            switch (dtype)
            {
            case DType.Float32:
                array = array.Cast <float>().ToArray();
                break;

            case DType.Float64:
                array = array.Cast <double>().ToArray();
                break;

            case DType.Int8:
                array = array.Cast <sbyte>().ToArray();
                break;

            case DType.Int16:
                array = array.Cast <short>().ToArray();
                break;

            case DType.Int32:
                array = array.Cast <int>().ToArray();
                break;

            case DType.Int64:
                array = array.Cast <long>().ToArray();
                break;

            case DType.UInt8:
                array = array.Cast <byte>().ToArray();
                break;

            case DType.UInt16:
                array = array.Cast <ushort>().ToArray();
                break;

            case DType.UInt32:
                array = array.Cast <uint>().ToArray();
                break;

            case DType.UInt64:
                array = array.Cast <ulong>().ToArray();
                break;

            case DType.Bool:
                array = array.Cast <bool>().ToArray();
                break;

            default:
                break;
            }

            return(new NDArray(array).reshape(x.shape));
        }
示例#2
0
 public static (int, int, int) iinfo(NDArray obj) => throw new NotImplementedException();