input: Write a function to optimize a given function using a while loop.
  assert optimize(lambda x: -np.sum((x - 3) ** 2), np.array([0, 0, 0]))[0] == 3
  assert optimize(lambda x: np.sum((x + 2) ** 2), np.array([0, 0, 0]))[0] == -2
  assert optimize(lambda x: -np.sum(x ** 2), np.array([1, 1, 1]))[0] == 0
output: import numpy as np
  
  def optimize(func, x0, learning_rate=0.01, tolerance=1e-6, max_iterations=1000):
      x = x0
      iteration = 0
      while iteration < max_iterations:
          grad = (func(x + tolerance) - func(x)) / tolerance
          new_x = x + learning_rate * grad
          
          if np.linalg.norm(new_x - x) < tolerance:
              break
          
          x = new_x
          iteration += 1
      
      return x