def triu(A, k=0, format=None):
 A = coo_matrix(A, copy=False)
 mask = ((A.row + k) <= A.col)
 return _masked_coo(A, mask).asformat(format)

def triu ( A , k = 0 , format = None ) : A = coo_matrix ( A , copy = False ) mask = ( ( A . row + k ) <= A . col ) return _masked_coo ( A , mask ) . asformat ( format )
upper triangle of an array .