Revision: 7205 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7205&view=rev Author: jdh2358 Date: 2009-06-09 16:47:46 +0000 (Tue, 09 Jun 2009)
Log Message: ----------- add rec_keep_fields w/ support for rec2txt Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/mlab.py Modified: trunk/matplotlib/lib/matplotlib/mlab.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mlab.py 2009-06-08 20:49:29 UTC (rev 7204) +++ trunk/matplotlib/lib/matplotlib/mlab.py 2009-06-09 16:47:46 UTC (rev 7205) @@ -2107,8 +2107,22 @@ return newrec +def rec_keep_fields(rec, names): + """ + Return a new numpy record array with only fields listed in names + """ + if cbook.is_string_like(names): + names = names.split(',') + + arrays = [] + for name in names: + arrays.append(rec[name]) + return np.rec.fromarrays(arrays, names=names) + + + def rec_groupby(r, groupby, stats): """ *r* is a numpy record array @@ -2699,7 +2713,7 @@ format.fmt = '%r' return format -def rec2txt(r, header=None, padding=3, precision=3): +def rec2txt(r, header=None, padding=3, precision=3, fields=None): """ Returns a textual representation of a record array. @@ -2714,6 +2728,10 @@ list of integers to apply precision individually. Precision for non-floats is simply ignored. + *fields* : if not None, a list of field names to print. fields + can be a list of strings like ['field1', 'field2'] or a single + comma separated string like 'field1,field2' + Example:: precision=[0,2,3] @@ -2725,6 +2743,9 @@ XYZ 6.32 -0.076 """ + if fields is not None: + r = rec_keep_fields(r, fields) + if cbook.is_numlike(precision): precision = [precision]*len(r.dtype) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins