Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 643d15b

Browse files
committed
added dtype patch from sf 1980695 for mlab.load
svn path=/trunk/matplotlib/; revision=5359
1 parent f7a9d04 commit 643d15b

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

lib/matplotlib/mlab.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ def save(fname, X, fmt='%.18e',delimiter=' '):
12001200

12011201

12021202
def load(fname,comments='#',delimiter=None, converters=None,skiprows=0,
1203-
usecols=None, unpack=False):
1203+
usecols=None, unpack=False, dtype=np.float_):
12041204
"""
12051205
Load ASCII data from fname into an array and return the array.
12061206
@@ -1230,8 +1230,9 @@ def load(fname,comments='#',delimiter=None, converters=None,skiprows=0,
12301230
a separator.
12311231
12321232
converters, if not None, is a dictionary mapping column number to
1233-
a function that will convert that column to a float. Eg, if
1234-
column 0 is a date string: converters={0:datestr2num}
1233+
a function that will convert that column to a float (or the optional
1234+
dtype if specified). Eg, if column 0 is a date string:
1235+
converters={0:datestr2num}
12351236
12361237
skiprows is the number of rows from the top to skip
12371238
@@ -1245,6 +1246,8 @@ def load(fname,comments='#',delimiter=None, converters=None,skiprows=0,
12451246
t,y = load('test.dat', unpack=True) # for two column data
12461247
x,y,z = load('somefile.dat', usecols=(3,5,7), unpack=True)
12471248
1249+
dtype, the array will have this dtype. default: numpy.float_
1250+
12481251
See examples/load_demo.py which exeercises many of these options.
12491252
"""
12501253

@@ -1270,15 +1273,15 @@ def splitfunc(x):
12701273
converterseq = [converters.get(j,float)
12711274
for j,val in enumerate(splitfunc(line))]
12721275
if usecols is not None:
1273-
vals = line.split(delimiter)
1276+
vals = splitfunc(line)
12741277
row = [converterseq[j](vals[j]) for j in usecols]
12751278
else:
12761279
row = [converterseq[j](val)
12771280
for j,val in enumerate(splitfunc(line))]
12781281
thisLen = len(row)
12791282
X.append(row)
12801283

1281-
X = np.array(X, np.float_)
1284+
X = np.array(X, dtype)
12821285
r,c = X.shape
12831286
if r==1 or c==1:
12841287
X.shape = max(r,c),

0 commit comments

Comments
 (0)