2

I save .npz files from Python and wanna read it in R.

I tried using npyLoad function but i get this error

library(RcppCNPy)
Data <- npyLoad("xx.npz")

Error in npyLoad("xx.npz") : header ended improperly

I think this happens because i saved my data from Python in Data array but i can't specify this in npyLoad.

So, is there away to read this compressed npy files in R. ?

coatless
  • 20,011
  • 13
  • 69
  • 84

1 Answers1

4

The issue linked by Dirk has a new comment that explains a workaround. The main idea is to use the reticulate package to access the numpy functionality.

library(reticulate)
np <- import("numpy")

npz1 <- np$load("foo1.npz")
npz1$files
npz1$f[["arr_0"]]
npz1$f[["arr_1"]]
Zach Boyd
  • 419
  • 1
  • 5
  • 23