code: def generate_swarm(
      n_particles, dimensions, bounds=None, center=1.00, init_pos=None
  ):
      """Generate a swarm
  
      Parameters
      ----------
      n_particles : int
          number of particles to be generated in the swarm.
      dimensions: int
          number of dimensions to be generated in the swarm
      bounds : tuple of numpy.ndarray or list, optional
          a tuple of size 2 where the first entry is the minimum bound while
          the second entry is the maximum bound. Each array must be of shape
          :code:`(dimensions,)`. Default is :code:`None`
      center : numpy.ndarray or float, optional
          controls the mean or center whenever the swarm is generated randomly.
          Default is :code:`1`
      init_pos : numpy.ndarray, optional
          option to explicitly set the particles' initial positions. Set to
          :code:`None` if you wish to generate the particles randomly.
          Default is :code:`None`.
  
      Returns
      -------
      numpy.ndarray
          swarm matrix of shape (n_particles, n_dimensions)
  
      Raises
      ------
      ValueError
          When the shapes and values of bounds, dimensions, and init_pos
          are inconsistent.
      TypeError
          When the argument passed to bounds is not an iterable.
      """
      try:
          if (init_pos is not None) and (bounds is None):
              pos = init_pos
          elif (init_pos is not None) and (bounds is not None):
              if not (
                  np.all(bounds[0] <= init_pos)
                  and np.all(init_pos <= bounds[1])
              ):
                  raise ValueError(
                      "User-defined init_pos is out of bounds."
                  )
              pos = init_pos
          elif (init_pos is None) and (bounds is None):
              pos = center * np.random.uniform(
                  low=0.0, high=1.0, size=(n_particles, dimensions)
              )
          else:
              lb, ub = bounds
              min_bounds = np.repeat(
                  np.array(lb)[np.newaxis, :], n_particles, axis=0
              )
              max_bounds = np.repeat(
                  np.array(ub)[np.newaxis, :], n_particles, axis=0
              )
              pos = center * np.random.uniform(
                  low=min_bounds,
                  high=max_bounds,
                  size=(n_particles, dimensions),
              )
      except ValueError:
          msg = "Bounds and/or init_pos should be of size ({},)"
          rep.logger.exception(msg.format(dimensions))
          raise
      except TypeError:
          msg = "generate_swarm() takes an int for n_particles and dimensions and an array for bounds"
          rep.logger.exception(msg)
          raise
      else:
          return pos
  
file_path: pyswarms/pyswarms/backend/generators.py
imports: import logging
  import numpy
  from ..utils.reporter import Reporter
  from .swarms import Swarm
label_desc: Use image node_id 1 for calling a global function with example usage: generate_swarm(n_particles, dimensions, bounds, center, init_pos) and returns: pos