简体   繁体   中英

a simple command — “np.save”, maybe i misunderstood

just working through the example for numpy.save -- http://docs.scipy.org/doc/numpy/reference/generated/numpy.save.html

Examples

from tempfile import TemporaryFile

outfile = TemporaryFile()

x = np.arange(10)

np.save(outfile, x)

AFTER this command (highlighted), why i could not find the output file called "outfile" in the current directory? sorry this may sound stupid

outfile.seek(0) # Only needed here to simulate closing & reopening file

np.load(outfile)

array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

It is because you are using - TemporaryFile , which is a temporary file which is not stored as outfile in your directory.

If you want to save it to outfile , you can give that as the name and it will save it to that file.

np.save('outfile',x)

When saving like that to load, you will need to use , again the filename as string -

np.load('outfile')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM