class_docstr: (n+1) x (m+1) Matrix
  Cell (i,j) corresponds to minimum total cost/distance of matching elements (i-1, j-1) in series1 and series2.
  
  Row 0 and column 0, are typically set to infinity, to prevent matching before the first element
class_docstr_tok: ["(","n+1",")","x","(","m+1",")","Matrix","Cell","(","i",",","j",")","corresponds","to","minimum","total","cost\/distance","of","matching","elements","(","i-1",",","j-1",")","in","series1","and","series2",".","Row","0","and","column","0",",","are","typically","set","to","infinity",",","to","prevent","matching","before","the","first","element"]
docstr: Creates a cost matrix from a window.
  Depending on the density of the active cells in the window,
  will select either a dense or sparse storage representation.
  
  Parameters
  ----------
  window
      Takes a `Window` defining which cells are active and which are empty
  
  Returns
  -------
  CostMatrix
docstr_tok: ["Creates","a","cost","matrix","from","a","window",".","Depending","on","the","density","of","the","active","cells","in","the","window",",","will","select","either","a","dense","or","sparse","storage","representation",".","Parameters","--","--","--","--","--","window","Takes","a","`","Window","`","defining","which","cells","are","active","and","which","are","empty","Returns","--","--","--","-","CostMatrix"]
code: def _from_window(window: Window):
      """
      Creates a cost matrix from a window.
      Depending on the density of the active cells in the window,
      will select either a dense or sparse storage representation.
  
      Parameters
      ----------
      window
          Takes a `Window` defining which cells are active and which are empty
  
      Returns
      -------
      CostMatrix
      """
      density = len(window) / ((window.n + 1) * (window.m + 1))
  
      # In the future it might be worth implementing
      # a sparse cost matrix based on column_index/column_length
      # that will work even for non-contiguous windows
      if isinstance(window, CRWindow) and density < 0.5:
          return SparseCostMatrix(window)
      else:
          return DenseCostMatrix(window.n, window.m)
  
imports: import array
  from abc import ABC, abstractmethod
  from itertools import repeat
  from typing import Tuple
  import numpy
  from .window import CRWindow, Window
label_desc: Use image node_id 6 for calling the CostMatrix obj's underlying member method code with example usage: obj._from_window(window) and returns: SparseCostMatrix, DenseCostMatrix