code: def log_softmax(x, axis=None):
      r"""
      Logarithm of softmax function::
  
          log_softmax(x) = log(softmax(x))
  
      Parameters
      ----------
      x : array_like
          Input array.
      axis : int or tuple of ints, optional
          Axis to compute values along. Default is None and softmax will be
          computed over the entire array `x`.
  
      Returns
      -------
      s : ndarray or scalar
          An array with the same shape as `x`. Exponential of the result will
          sum to 1 along the specified axis. If `x` is a scalar, a scalar is
          returned.
  
      Notes
      -----
      `log_softmax` is more accurate than ``np.log(softmax(x))`` with inputs that
      make `softmax` saturate (see examples below).
  
      .. versionadded:: 1.5.0
  
      Examples
      --------
      >>> from scipy.special import log_softmax
      >>> from scipy.special import softmax
      >>> np.set_printoptions(precision=5)
  
      >>> x = np.array([1000.0, 1.0])
  
      >>> y = log_softmax(x)
      >>> y
      array([   0., -999.])
  
      >>> with np.errstate(divide='ignore'):
      ...   y = np.log(softmax(x))
      ...
      >>> y
      array([  0., -inf])
  
      """
  
      x = _asarray_validated(x, check_finite=False)
  
      x_max = np.amax(x, axis=axis, keepdims=True)
  
      if x_max.ndim > 0:
          x_max[~np.isfinite(x_max)] = 0
      elif not np.isfinite(x_max):
          x_max = 0
  
      tmp = x - x_max
      exp_tmp = np.exp(tmp)
  
      # suppress warnings about log of zero
      with np.errstate(divide="ignore"):
          s = np.sum(exp_tmp, axis=axis, keepdims=True)
          out = np.log(s)
  
      out = tmp - out
      return out
  
imports: import numpy
  from scipy._lib._util import _asarray_validated
label_desc: Use image node_id 3 for calling a global function with example usage: log_softmax(x, axis) and returns: out