Englighted by #80, I have implemented a new initialization of the NDArray directly from a string representation, which I found quite useful.
NDArray initialization from string representation of an ndarray.
The shape can be inferred from the string representation.
The literals will be casted to the dtype of the NDArray.
Note:
StringLiteral is also allowed as input as it is coerced to String type before it is passed into the function.
Example:
import numojo as nm
fn main() raises:
var A = nm.NDArray[DType.int8]("[[[1,2],[3,4]],[[5,6],[7,8]]]")
var B = nm.NDArray[DType.float16]("[[1,2,3,4],[5,6,7,8]]")
var C = nm.NDArray("[0.1, -2.3, 41.5, 19.29145, -199]")
var D = nm.NDArray[DType.int32]("[0.1, -2.3, 41.5, 19.29145, -199]")
print(A)
print(B)
print(C)
print(D)
The output goes as follows. Note that the numbers are automatically casted to the dtype of the NDArray.
Englighted by #80, I have implemented a new initialization of the NDArray directly from a string representation, which I found quite useful.
NDArray initialization from string representation of an ndarray. The shape can be inferred from the string representation. The literals will be casted to the dtype of the NDArray.
Note: StringLiteral is also allowed as input as it is coerced to String type before it is passed into the function.
Example:
The output goes as follows. Note that the numbers are automatically casted to the dtype of the NDArray.