python - How to output a Numpy array to a file object for Picloud -
i have matrix-factorization process i'm running on picloud. output set of numpy arrays (ndarray).
now, want save bucket, i'm not able 0 in on right way it. let's assume array saved p.
i tried:
cloud.bucket.putf(p,'p.csv')
but returned error: "ioerror: file object not seekable. cannot transmit".
i tried
numpy.ndarray.tofile(p,f, sep=",", format="%s") #outputing array file object f cloud.bucket.putf(f,'p.csv') #saving file object f in bucket.
i tried couple of other things, including using using numpy.savetext (as if ran locally) i'm not able solve between picloud documentation , stackexchange questions. haven't tried pickle yet, though. felt straightforward, i'm feeling quite silly after spending few hours on this.
as guessed, want pickle array follows:
import cloud import cpickle pickle # write cloud.bucket.putf(pickle.dumps(p), 'p.csv') # read obj = pickle.loads(cloud.bucket.getf('p.csv').read())
this general way serialize , store python object in picloud bucket. recommend store csv files under prefix keep organized [1].
[1] http://docs.picloud.com/bucket.html#namespacing-with-prefix
Comments
Post a Comment