code: def compute_pbest(swarm):
      """Update the personal best score of a swarm instance
  
      You can use this method to update your personal best positions.
  
      .. code-block:: python
  
          import pyswarms.backend as P
          from pyswarms.backend.swarms import Swarm
  
          my_swarm = P.create_swarm(n_particles, dimensions)
  
          # Inside the for-loop...
          for i in range(iters):
              # It updates the swarm internally
              my_swarm.pbest_pos, my_swarm.pbest_cost = P.update_pbest(my_swarm)
  
      It updates your :code:`current_pbest` with the personal bests acquired by
      comparing the (1) cost of the current positions and the (2) personal
      bests your swarm has attained.
  
      If the cost of the current position is less than the cost of the personal
      best, then the current position replaces the previous personal best
      position.
  
      Parameters
      ----------
      swarm : pyswarms.backend.swarm.Swarm
          a Swarm instance
  
      Returns
      -------
      numpy.ndarray
          New personal best positions of shape :code:`(n_particles, n_dimensions)`
      numpy.ndarray
          New personal best costs of shape :code:`(n_particles,)`
      """
      try:
          # Infer dimensions from positions
          dimensions = swarm.dimensions
          # Create a 1-D and 2-D mask based from comparisons
          mask_cost = swarm.current_cost < swarm.pbest_cost
          mask_pos = np.repeat(
              mask_cost[:, np.newaxis], dimensions, axis=1
          )
          # Apply masks
          new_pbest_pos = np.where(
              ~mask_pos, swarm.pbest_pos, swarm.position
          )
          new_pbest_cost = np.where(
              ~mask_cost, swarm.pbest_cost, swarm.current_cost
          )
      except AttributeError:
          rep.logger.exception(
              "Please pass a Swarm class. You passed {}".format(
                  type(swarm)
              )
          )
          raise
      else:
          return (new_pbest_pos, new_pbest_cost)
  
file_path: pyswarms/pyswarms/backend/operators.py
imports: import logging
  import numpy
  from ..utils.reporter import Reporter
  from .handlers import BoundaryHandler, VelocityHandler
  from functools import partial
label_desc: Use image node_id 1 for calling a global function with example usage: compute_pbest(swarm) and returns: new_pbest_pos,  new_pbest_cost