code: def monotonicity_prox(tensor, decreasing=False):
      """
      This function projects each column of the input array on the set of arrays so that
            x[1] <= x[2] <= ... <= x[n] (decreasing=False)
                          or
            x[1] >= x[2] >= ... >= x[n] (decreasing=True)
      is satisfied columnwise.
  
      Parameters
      ----------
      tensor : ndarray
      decreasing : If it is True, function returns columnwise
                   monotone decreasing tensor. Otherwise, returned array
                   will be monotone increasing.
                   Default: True
  
      Returns
      -------
      ndarray
            A tensor of which columns' are monotonic.
  
      References
      ----------
      .. [1]: G. Chierchia, E. Chouzenoux, P. L. Combettes, and J.-C. Pesquet
              "The Proximity Operator Repository. User's guide"
      """
      if tl.ndim(tensor) == 1:
          tensor = tl.reshape(tensor, [tl.shape(tensor)[0], 1])
      elif tl.ndim(tensor) > 2:
          raise ValueError(
              "Monotonicity prox doesn't support an input which has more than 2 dimensions."
          )
      tensor_mon = tl.copy(tensor)
      if decreasing:
          tensor_mon = tl.flip(tensor_mon, axis=0)
      row, column = tl.shape(tensor_mon)
      cum_sum = tl.cumsum(tensor_mon, axis=0)
      for j in range(column):
          assisted_tensor = tl.zeros([row, row])
          for i in range(row):
              if i == 0:
                  assisted_tensor = tl.index_update(
                      assisted_tensor,
                      tl.index[i, i:],
                      cum_sum[i:, j]
                      / tl.tensor(
                          tl.arange(row - i) + 1, **tl.context(tensor)
                      ),
                  )
              else:
                  assisted_tensor = tl.index_update(
                      assisted_tensor,
                      tl.index[i, i:],
                      (cum_sum[i:, j] - cum_sum[i - 1, j])
                      / tl.tensor(
                          tl.arange(row - i) + 1, **tl.context(tensor)
                      ),
                  )
          tensor_mon = tl.index_update(
              tensor_mon,
              tl.index[:, j],
              tl.max(assisted_tensor, axis=0),
          )
          for i in reversed(range(row - 1)):
              if tensor_mon[i, j] > tensor_mon[i + 1, j]:
                  tensor_mon = tl.index_update(
                      tensor_mon, tl.index[i, j], tensor_mon[i + 1, j]
                  )
      if decreasing:
          tensor_mon = tl.flip(tensor_mon, axis=0)
      return tensor_mon
  
file_path: tensorly/tensorly/tenalg/proximal.py
imports: import tensorly
  import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: monotonicity_prox(tensor, decreasing) and returns: tensor_mon