code: def tricu(P, k=0):
      
      tri = numpy.sum(numpy.mgrid[[slice(0,_,1) for _ in P.shape]], 0)
      tri = tri<len(tri) + k
  
      if isinstance(P, Poly):
          A = P.A.copy()
          B = {}
          for key in P.keys:
              B[key] = A[key]*tri
          return Poly(B, shape=P.shape, dim=P.dim, dtype=P.dtype)
  
      out = P*tri
      return out
docs: Cross-diagonal upper triangle.