code: def rotate(matrix, angle):
      r
  
      shape = np.array(matrix.shape)
  
      if shape[0] != shape[1]:
          raise ValueError('Input matrix must be square.')
  
      shift = (shape - 1) // 2
  
      index = np.array(list(product(*np.array([np.arange(val) for val in
                       shape])))) - shift
  
      new_index = np.array(np.dot(index, rot_matrix(angle)), dtype='int') + shift
      new_index[new_index >= shape[0]] -= shape[0]
  
      return matrix[tuple(zip(new_index.T))].reshape(shape.T)
docs: r"""Rotate
  
      This method rotates an input matrix about the input angle.
  
      Parameters
      ----------
      matrix : np.ndarray
          Input matrix array
      angle : float
          Rotation angle in radians
  
      Returns
      -------
      np.ndarray rotated matrix
  
      Raises
      ------
      ValueError
          For invalid matrix shape
  
      Examples
      --------
      >>> from modopt.math.matrix import rotate
      >>> a = np.arange(9).reshape(3, 3)
      >>> rotate(a, np.pi / 2)
      array([[2, 5, 8],
             [1, 4, 7],
             [0, 3, 6]])