summaryrefslogtreecommitdiff
path: root/io.py
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2007-12-16 05:30:41 +0000
committerTravis Oliphant <oliphant@enthought.com>2007-12-16 05:30:41 +0000
commit25c161b20770bd9c00c106f21019d2593953dbfd (patch)
tree9bf29617b88aaeb298b9f987c2ee17c037fe3814 /io.py
parent22fbdc5c744674550be074550862645ddf423b31 (diff)
downloadnumpy-25c161b20770bd9c00c106f21019d2593953dbfd.tar.gz
Changes to io layer of NumPy
Diffstat (limited to 'io.py')
-rw-r--r--io.py62
1 files changed, 23 insertions, 39 deletions
diff --git a/io.py b/io.py
index 6872b633a..169dc8f54 100644
--- a/io.py
+++ b/io.py
@@ -1,10 +1,12 @@
-__all__ = ['savetxt', 'loadtxt',
- 'dump', 'dumps', 'loads',
- 'save', 'load',
- 'DataFile']
-
-from cPickle import load as _cload, loads, dump as _cdump, dumps as _cdumps
+__all__ = ['savetxt', 'loadtxt',
+ 'loads', 'load',
+ 'save', 'savez',
+ 'DataFile',
+ 'unpackbits',
+ 'packbits']
+
+from cPickle import load as _cload, loads
from _datasource import DataFile
_file = file
@@ -30,48 +32,30 @@ def load(file):
# if pickle:
return _cload(file)
-def dumps(*args):
- """Dump an array or multiple arrays to a pickle string
- """
- return _cdumps(args, protocol=2)
-def dump(file, *args):
- """Dump an array or multiple arrays to a pickle file.
- Multiple arrays are placed in a tuple before pickling.
- The file can be a string or an open file-like object.
+class _bagobj(object):
+ def __init__(self, **kwds):
+ self.__dict__.update(kwds)
- Example:
- --------
- import numpy as np
- ...
- np.dump('myfile.pkl', a, b, c)
- a,b,c = np.load('myfile.pkl')
- """
- if isinstance(file, type("")):
- file = _file(file, "wb")
- _cdump(args, file, protocol=2)
+class _npz_obj(dict):
+ pass
-def save(file, *args):
- """Save an array or multiple arrays to a binary file.
+def save(file, arr):
+ """Save an array to a binary file (specified as a string or file-like object).
+
+ If the file is a string, then if it does not have the .npy extension, it is appended
+ and a file open.
+
+ Data is saved to the open file in NumPy-array format
- If the file is a string with a .pkl extension, then the binary file
- is a pickle file. Otherwise, the file is saved as a numpy, binary file.
- The file can be a string or an open file-like object.
-
Example:
--------
import numpy as np
...
- np.dump('myfile.npy', a, b, c)
- a,b,c = np.load('myfile.npy')
- """
-
- if issinstance(file, type("")):
- if file.endswith('.pkl'):
- return dump(file, *args)
- file = _file(file, "wb")
-
+ np.save('myfile', a)
+ a = np.load('myfile.npy')
+ """
# code to save to numpy binary here...