diff options
author | Jarrod Millman <millman@berkeley.edu> | 2008-04-20 11:49:35 +0000 |
---|---|---|
committer | Jarrod Millman <millman@berkeley.edu> | 2008-04-20 11:49:35 +0000 |
commit | 8c663313de36e860bbfea0909de181d330bfdfc7 (patch) | |
tree | a7b5f3585d2b8a2d8307bfb03dd0e449fa732860 /numpy/lib/io.py | |
parent | cb7de97f089b67eaacf37ddbebcfb91c292c0ef4 (diff) | |
download | numpy-8c663313de36e860bbfea0909de181d330bfdfc7.tar.gz |
ran reindent in preparation for the 1.1 release
Diffstat (limited to 'numpy/lib/io.py')
-rw-r--r-- | numpy/lib/io.py | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/numpy/lib/io.py b/numpy/lib/io.py index 9e61ab2f8..4c7180245 100644 --- a/numpy/lib/io.py +++ b/numpy/lib/io.py @@ -232,37 +232,37 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, converters=None, Parameters ---------- - fname : filename or a file handle. + fname : filename or a file handle. Support for gzipped files is automatic, if the filename ends in .gz - dtype : data-type - Data type of the resulting array. If this is a record data-type, the - resulting array will be 1-d and each row will be interpreted as an - element of the array. The number of columns used must match the number + dtype : data-type + Data type of the resulting array. If this is a record data-type, the + resulting array will be 1-d and each row will be interpreted as an + element of the array. The number of columns used must match the number of fields in the data-type in this case. - comments : str + comments : str The character used to indicate the start of a comment in the file. delimiter : str - A string-like character used to separate values in the file. If delimiter + A string-like character used to separate values in the file. If delimiter is unspecified or none, any whitespace string is a separator. converters : {} - A dictionary mapping column number to a function that will convert that - column to a float. Eg, if column 0 is a date string: - converters={0:datestr2num}. Converters can also be used to provide - a default value for missing data: converters={3:lambda s: float(s or 0)}. - + A dictionary mapping column number to a function that will convert that + column to a float. Eg, if column 0 is a date string: + converters={0:datestr2num}. Converters can also be used to provide + a default value for missing data: converters={3:lambda s: float(s or 0)}. + skiprows : int The number of rows from the top to skip. usecols : sequence - A sequence of integer column indexes to extract where 0 is the first + A sequence of integer column indexes to extract where 0 is the first column, eg. usecols=(1,4,5) will extract the 2nd, 5th and 6th columns. unpack : bool - If True, will transpose the matrix allowing you to unpack into named + If True, will transpose the matrix allowing you to unpack into named arguments on the left hand side. Examples @@ -271,8 +271,8 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, converters=None, >>> x,y,z = load('somefile.dat', usecols=(3,5,7), unpack=True) >>> r = np.loadtxt('record.dat', dtype={'names':('gender','age','weight'), 'formats': ('S1','i4', 'f4')}) - - SeeAlso: scipy.io.loadmat to read and write matfiles. + + SeeAlso: scipy.io.loadmat to read and write matfiles. """ if _string_like(fname): @@ -332,23 +332,23 @@ def savetxt(fname, X, fmt='%.18e',delimiter=' '): Parameters ---------- fname : filename or a file handle - If the filename ends in .gz, the file is automatically saved in - compressed gzip format. The load() command understands gzipped files + If the filename ends in .gz, the file is automatically saved in + compressed gzip format. The load() command understands gzipped files transparently. X : array or sequence Data to write to file. - fmt : string - A format string %[flags][width][.precision]specifier. See notes below for + fmt : string + A format string %[flags][width][.precision]specifier. See notes below for a description of some common flags and specifiers. delimiter : str Character separating columns. - + Examples -------- >>> savetxt('test.out', x, delimiter=',') # X is an array >>> savetxt('test.out', (x,y,z)) # x,y,z equal sized 1D arrays - >>> savetxt('test.out', x, fmt='%1.4e') # use exponential notation - + >>> savetxt('test.out', x, fmt='%1.4e') # use exponential notation + Notes on fmt ------------ flags: @@ -362,19 +362,19 @@ def savetxt(fname, X, fmt='%.18e',delimiter=' '): For e, E and f specifiers, the number of digits to print after the decimal point. For g and G, the maximum number of significant digits. - For s, the maximum number of characters. + For s, the maximum number of characters. specifiers: c : character d or i : signed decimal integer - e or E : scientific notation with e or E. + e or E : scientific notation with e or E. f : decimal floating point g,G : use the shorter of e,E or f o : signed octal s : string of characters u : unsigned decimal integer x,X : unsigned hexadecimal integer - - This is not an exhaustive specification. + + This is not an exhaustive specification. """ if _string_like(fname): @@ -403,7 +403,7 @@ def savetxt(fname, X, fmt='%.18e',delimiter=' '): import re def fromregex(file, regexp, dtype): """Construct a record array from a text file, using regular-expressions parsing. - + Array is constructed from all matches of the regular expression in the file. Groups in the regular expression are converted to fields. @@ -423,7 +423,7 @@ def fromregex(file, regexp, dtype): >>> f.write("1312 foo\n1534 bar\n 444 qux") >>> f.close() >>> np.fromregex('test.dat', r"(\d+)\s+(...)", [('num', np.int64), ('key', 'S3')]) - array([(1312L, 'foo'), (1534L, 'bar'), (444L, 'qux')], + array([(1312L, 'foo'), (1534L, 'bar'), (444L, 'qux')], dtype=[('num', '<i8'), ('key', '|S3')]) """ @@ -433,7 +433,7 @@ def fromregex(file, regexp, dtype): regexp = re.compile(regexp) if not isinstance(dtype, np.dtype): dtype = np.dtype(dtype) - + seq = regexp.findall(file.read()) if seq and not isinstance(seq[0], tuple): # make sure np.array doesn't interpret strings as binary data @@ -441,4 +441,3 @@ def fromregex(file, regexp, dtype): seq = [(x,) for x in seq] output = np.array(seq, dtype=dtype) return output - |