Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6342#discussion_r33807633
  
    --- Diff: python/pyspark/mllib/linalg.py ---
    @@ -876,6 +881,50 @@ 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)
    +        DenseMatrix([[ 0.,  2.],
    +                     [ 1.,  3.]])
    +        >>> dm = DenseMatrix(2, 2, range(4), isTransposed=True)
    +        >>> print(dm)
    +        DenseMatrix([[ 0.,  1.],
    +                     [ 2.,  3.]])
    +        """
    +        # Inspired by __repr__ in scipy matrices.
    +        array_lines = repr(self.toArray()).splitlines()
    +
    +        # We need to adjust six spaces which is the difference in number
    +        # of letters between "DenseMatrix" and "array"
    +        x = '\n'.join([(" " * 6 + line) for line in array_lines[1:]])
    +        return array_lines[0].replace("array", "DenseMatrix") + "\n" + x
    +
    +    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)
    +        """
    +        # If the number of values are less than seven then return as it is.
    +        # Else return first three values and last three values.
    +        if len(self.values) <= 6:
    --- End diff --
    
    `<= 6` -> `< 7` to match the comment, or you can change the comment


---
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]

Reply via email to