code: def _get_bw(x, bw, grid_counts=None, x_std=None, x_range=None):
      """Compute bandwidth for a given data `x` and `bw`.
  
      Also checks `bw` is correctly specified.
  
      Parameters
      ----------
      x : 1-D numpy array
          1 dimensional array of sample data from the
          variable for which a density estimate is desired.
      bw: int, float or str
          If numeric, indicates the bandwidth and must be positive.
          If str, indicates the method to estimate the bandwidth.
  
      Returns
      -------
      bw: float
          Bandwidth
      """
      if isinstance(bw, bool):
          raise ValueError(
              (
                  "`bw` must not be of type `bool`.\n"
                  "Expected a positive numeric or one of the following strings:\n"
                  f"{list(_BW_METHODS_LINEAR)}."
              )
          )
      if isinstance(bw, (int, float)):
          if bw < 0:
              raise ValueError(
                  f"Numeric `bw` must be positive.\nInput: {bw:.4f}."
              )
      elif isinstance(bw, str):
          bw_lower = bw.lower()
  
          if bw_lower not in _BW_METHODS_LINEAR:
              raise ValueError(
                  "Unrecognized bandwidth method.\n"
                  f"Input is: {bw_lower}.\n"
                  f"Expected one of: {list(_BW_METHODS_LINEAR)}."
              )
  
          bw_fun = _BW_METHODS_LINEAR[bw_lower]
          bw = bw_fun(
              x, grid_counts=grid_counts, x_std=x_std, x_range=x_range
          )
      else:
          raise ValueError(
              "Unrecognized `bw` argument.\n"
              "Expected a positive numeric or one of the following strings:\n"
              f"{list(_BW_METHODS_LINEAR)}."
          )
      return bw
  
imports: import warnings
  import numpy
  from scipy.fftpack import fft
  from scipy.optimize import brentq
  from scipy.signal import convolve, convolve2d, gaussian
  from scipy.sparse import coo_matrix
  from scipy.special import ive
  from ..utils import _cov, _dot, _stack, conditional_jit
label_desc: Use image node_id 6 for calling a global function with example usage: _get_bw(x, bw, grid_counts, x_std, x_range) and returns: bw