Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/6342#discussion_r32780890
--- Diff: python/pyspark/mllib/linalg.py ---
@@ -821,6 +822,36 @@ def __reduce__(self):
self.numRows, self.numCols, self.values.tostring(),
int(self.isTransposed))
+ def __str__(self):
+ """
+ Pretty printing of a DenseMatrix
+
+ >>> dm = DenseMatrix(2, 2, range(4))
+ >>> print(dm)
+ 0.0 2.0
+ 1.0 3.0
+ >>> dm = DenseMatrix(2, 2, range(4), isTransposed=True)
+ >>> print(dm)
+ 0.0 1.0
+ 2.0 3.0
+ """
+ ds = []
+ for row in self.toArray():
+ ds.append(" ".join([str(col) for col in row]))
+ return "\n".join(ds)
+
+ def __repr__(self):
+ """
+ Representation of a DenseMatrix
+
+ >>> dm = DenseMatrix(2, 2, range(4))
+ >>> dm
+ DenseMatrix(2, 2, [0.0, 1.0, 2.0, 3.0], False)
+ """
+ entries = ', '.join([_format_float(val) for val in self.values])
--- End diff --
We shouldn't always display all elements in case there are millions of
them. Again, it would be nice to reuse numpy's implementation.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]