diff options
author | Hameer Abbasi <einstein.edison@gmail.com> | 2019-10-08 02:22:41 +0500 |
---|---|---|
committer | Hameer Abbasi <einstein.edison@gmail.com> | 2019-10-08 02:22:41 +0500 |
commit | 2246f68b1af3f27bce9cbee3a49aa10e1dd7cb80 (patch) | |
tree | 6eaa55f3167512cc044304512be5ac87f215d9ff /numpy/lib/npyio.py | |
parent | 750a59e9310ff1226ff2912fc29a815c2ce07ed2 (diff) | |
parent | d2c57616d369fdb5b4ea22b77d314785b1a0508e (diff) | |
download | numpy-2246f68b1af3f27bce9cbee3a49aa10e1dd7cb80.tar.gz |
Merge branch 'uarray' into uarray-me
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r-- | numpy/lib/npyio.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index b9dc444f8..e57a6dd47 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -506,7 +506,9 @@ def save(file, arr, allow_pickle=True, fix_imports=True): Notes ----- For a description of the ``.npy`` format, see :py:mod:`numpy.lib.format`. - + + Any data saved to the file is appended to the end of the file. + Examples -------- >>> from tempfile import TemporaryFile @@ -519,6 +521,15 @@ def save(file, arr, allow_pickle=True, fix_imports=True): >>> np.load(outfile) array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) + + >>> with open('test.npy', 'wb') as f: + ... np.save(f, np.array([1, 2])) + ... np.save(f, np.array([1, 3])) + >>> with open('test.npy', 'rb') as f: + ... a = np.load(f) + ... b = np.load(f) + >>> print(a, b) + # [1 2] [1 3] """ own_fid = False if hasattr(file, 'write'): @@ -1776,12 +1787,13 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, replace_space=replace_space) # Skip the first `skip_header` rows - for i in range(skip_header): - next(fhd) - - # Keep on until we find the first valid values - first_values = None try: + for i in range(skip_header): + next(fhd) + + # Keep on until we find the first valid values + first_values = None + while not first_values: first_line = _decode_line(next(fhd), encoding) if (names is True) and (comments is not None): @@ -2168,7 +2180,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, outputmask = np.array(masks, dtype=mdtype) else: # Overwrite the initial dtype names if needed - if names and dtype.names: + if names and dtype.names is not None: dtype.names = names # Case 1. We have a structured type if len(dtype_flat) > 1: @@ -2218,7 +2230,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, # output = np.array(data, dtype) if usemask: - if dtype.names: + if dtype.names is not None: mdtype = [(_, bool) for _ in dtype.names] else: mdtype = bool |