| convert_bytes_to_array | R Documentation |
This is a replacement for readBin() that can handle the various data types
and endianness specified in the .npy file header.
convert_bytes_to_array(bytes, what, shape, size, endian)
bytes |
A raw vector containing the bytes to convert |
what |
A character specifying the base type to convert to (e.g.,
|
shape |
A numeric vector with desired shape of the output array |
size |
A numeric value with the number of bytes per element for the specified type |
endian |
The endianness of the data ( |
An R array containing the converted data, with the specified shape and data type.
x <- matrix(c(3L, 6L, 2L, 1L, 12L, 0L), nrow = 2, ncol = 3)
x
y <- writeBin(c(x), raw()) |>
convert_bytes_to_array(
"int",
shape = c(2L, 3L),
size = 4L,
endian = "little"
)
y
dim(y)
is.array(y)
storage.mode(y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.