python - Loading numpy arrays stored in npz archive in PySpark -


i have large number of numpy arrays in s3 stored in npz archive. best way load them pyspark rdd/dataframe of numpy arrays? have tried load file using sc.wholetextfiles api.

rdd=sc.wholetextfiles("s3://[bucket]/[folder_containing_npz_files]")  

however numpy.load requires file handle. , loading file contents in memory string takes lot of memory.

you cannot memory requirements otherwise bytesio should work fine:

from io import bytesio  def extract(kv):     k, v = kv     bytesio(v) r:         f, x in np.load(r).items():             yield "{0}\t{1}".format(k, f), x  sc.binaryfiles(inputpath).flatmap(extract) 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -