code: def to_pattern_matrix(D):
      
      result = np.zeros_like(D)
      # This is a cleverer way of doing
      #
      #     for (u, v) in zip(*(D.nonzero())):
      #         result[u, v] = 1
      #
      result[D.nonzero()] = 1
      return result
docs: Returns the Boolean matrix in the same shape as `D` with ones exactly
      where there are nonzero entries in `D`.
  
      `D` must be a NumPy array.