From 3f38cbfb348a4322ca6bb96029f60745c57989b6 Mon Sep 17 00:00:00 2001 From: wirawan Date: Tue, 13 Sep 2011 21:50:16 +0000 Subject: [PATCH] * Allow printing of numpy.matrix objects. --- text_tools.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/text_tools.py b/text_tools.py index adfb133..86637ba 100644 --- a/text_tools.py +++ b/text_tools.py @@ -1,4 +1,4 @@ -# $Id: text_tools.py,v 1.7 2011-09-07 15:03:54 wirawan Exp $ +# $Id: text_tools.py,v 1.8 2011-09-13 21:50:16 wirawan Exp $ # # wpylib.text_tools # Created: 20091204 @@ -49,6 +49,8 @@ def vector_str(M, fmt="%22.15g", V=False): return " ".join([ fmt % m for m in M ]) def matrix_str(M, fmt="%22.15g"): + if isinstance(M, numpy.matrix): + M = numpy.asarray(M) if len(M.shape) != 2: raise ValueError, "Wrong shape: expecting a two-dimensional array." return "\n".join([ " ".join([ fmt % c for c in R ] ) for R in M ])