code: def count_events(events, ids=None):
      """Count events.
  
      Parameters
      ----------
      events : ndarray, shape (N, 3)
          The events array (consisting of N events).
      ids : array-like of int | None
          If ``None``, count all event types present in the input. If array-like
          of int, count only those event types given by ``ids``.
  
      Returns
      -------
      counts : dict
          A dictionary containing the event types as keys with their counts as
          values.
  
      Examples
      --------
          >>> events = np.array([[0, 0, 1], [0, 0, 1], [0, 0, 5]])
          >>> count_events(events)
          {1: 2, 5: 1}
          >>> count_events(events, ids=[1, 5])
          {1: 2, 5: 1}
          >>> count_events(events, ids=[1, 11])
          {1: 2, 11: 0}
      """
      counts = np.bincount(events[:, 2])
      counts = {
          i: int(count) for i, count in enumerate(counts) if count > 0
      }
      if ids is not None:
          counts = {id_: counts.get(id_, 0) for id_ in ids}
      return counts
  
imports: from collections.abc import Sequence
  from pathlib import Path
  import numpy
  from ._fiff.constants import FIFF
  from ._fiff.open import fiff_open
  from ._fiff.pick import pick_channels
  from ._fiff.tag import read_tag
  from ._fiff.tree import dir_tree_find
  from ._fiff.write import end_block, start_and_end_file, start_block, write_int
  from .utils import _check_fname, _check_integer_or_list, _check_on_missing, _check_option, _get_stim_channel, _on_missing, _pl, _validate_type, check_fname, fill_doc, logger, verbose, warn
label_desc: Use image node_id 17 for calling a global function with example usage: count_events(events, ids) and returns: counts