#NEWLINE# def triu( A , k = 0 , format = None ) : #NEWLINE# #INDENT# 'Return the upper triangular portion of a matrix in sparse format\n\n    Returns the elements on or above the k-th diagonal of the matrix A.\n        - k = 0 corresponds to the main diagonal\n        - k > 0 is above the main diagonal\n        - k < 0 is below the main diagonal\n\n    Parameters\n    ----------\n    A : dense or sparse matrix\n        Matrix whose upper trianglar portion is desired.\n    k : integer : optional\n        The bottom-most diagonal of the upper triangle.\n    format : string\n        Sparse format of the result, e.g. format="csr", etc.\n\n    Returns\n    -------\n    L : sparse matrix\n        Upper triangular portion of A in sparse format.\n\n    See Also\n    --------\n    tril : lower triangle in sparse format\n\n    Examples\n    --------\n    >>> from scipy.sparse import csr_matrix, triu\n    >>> A = csr_matrix([[1, 2, 0, 0, 3], [4, 5, 0, 6, 7], [0, 0, 8, 9, 0]],\n    ...                dtype=\'int32\')\n    >>> A.toarray()\n    array([[1, 2, 0, 0, 3],\n           [4, 5, 0, 6, 7],\n           [0, 0, 8, 9, 0]])\n    >>> triu(A).toarray()\n    array([[1, 2, 0, 0, 3],\n           [0, 5, 0, 6, 7],\n           [0, 0, 8, 9, 0]])\n    >>> triu(A).nnz\n    8\n    >>> triu(A, k=1).toarray()\n    array([[0, 2, 0, 0, 3],\n           [0, 0, 0, 6, 7],\n           [0, 0, 0, 9, 0]])\n    >>> triu(A, k=-1).toarray()\n    array([[1, 2, 0, 0, 3],\n           [4, 5, 0, 6, 7],\n           [0, 0, 8, 9, 0]])\n    >>> triu(A, format=\'csc\')\n    <3x5 sparse matrix of type \'<type \'numpy.int32\'>\'\n            with 8 stored elements in Compressed Sparse Column format>\n\n    ' #NEWLINE# A = coo_matrix ( A , copy = False ) #NEWLINE# mask = ( ( A . row + k ) <= A . col ) #NEWLINE# return _masked_coo ( A , mask ) . asformat ( format )