| vol_read_npy | R Documentation |
Reads a .npy file into an R array, without calling Python.
The format is a short ASCII header followed by the raw buffer, so no
package is needed to parse it.
vol_read_npy(path)
path |
Path to a |
Read a NumPy array file
The reader covers the little-endian and big-endian floating-point
types f4 and f8, the signed integer types i1, i2, i4 and i8,
the unsigned integer types u1, u2 and u4, and the boolean type b1.
An unsigned u4 file returns doubles, since its values may pass the
largest R integer; any other type is refused.
C order is the default that NumPy writes and is transposed on the way in,
so dim() of the result matches the shape field of the header. A
Fortran-ordered file is refused rather than read wrongly.
Values are carried across exactly. A f4 file widens to double with no
loss, since every single-precision number is a double-precision number.
An array of the shape the header states, of type double for a floating-point file, integer for an integer file and logical for a boolean file. A one-dimensional file returns a bare vector.
van der Walt, S., Colbert, S. C., & Varoquaux, G. (2011). The NumPy array: a structure for efficient numerical computation. Computing in Science & Engineering, 13(2), 22-30. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1109/MCSE.2011.37")}
vol_field() to wrap arrays as a field, vol_read_netcdf() for the
other format the reader accepts, vol_payload() to build the browser
payload from a field.
a <- vol_read_npy(system.file("extdata", "example.npy", package = "volumr"))
dim(a)
a
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.