/// <summary> /// Creates a scalar <see cref="NDArray"/> of <see cref="value"/> and <see cref="dtype"/>. /// </summary> /// <param name="value">The value of the scalar</param> /// <param name="typeCode">The type code of the scalar.</param> /// <returns></returns> /// <remarks>In case when <see cref="value"/> is not <see cref="dtype"/>, <see cref="Convert.ChangeType(object,System.Type)"/> will be called.</remarks> public static NDArray Scalar(object value, NPTypeCode typeCode) { var type = typeCode.AsType(); var ndArray = new NDArray(type, new int[0]); ndArray.Storage.ReplaceData(Arrays.Wrap(typeCode, Convert.ChangeType(value, type))); //todo! create a NPConvert to support NPTypeCode return(ndArray); }
/// <summary> /// Construct an array from data in a text or binary file. /// A highly efficient way of reading binary data with a known data-type, as well as parsing simply formatted text files. Data written using the tofile method can be read using this function. /// </summary> /// <param name="file">filename.</param> /// <param name="dtype">Data type of the returned array. For binary files, it is used to determine the size and byte-order of the items in the file.</param> /// <returns></returns> /// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.fromfile.html</remarks> public static NDArray fromfile(string file, NPTypeCode dtype) { return fromfile(file, dtype.AsType()); }