class_docstr: Initialize a `DiscreteFactor` class.
  
  Defined above, we have the following mapping from variable
  assignments to the index of the row vector in the value field:
  +-----+-----+-----+-------------------+
  |  x1 |  x2 |  x3 |    phi(x1, x2, x3)|
  +-----+-----+-----+-------------------+
  | x1_0| x2_0| x3_0|     phi.value(0)  |
  +-----+-----+-----+-------------------+
  | x1_0| x2_0| x3_1|     phi.value(1)  |
  +-----+-----+-----+-------------------+
  | x1_0| x2_1| x3_0|     phi.value(2)  |
  +-----+-----+-----+-------------------+
  | x1_0| x2_1| x3_1|     phi.value(3)  |
  +-----+-----+-----+-------------------+
  | x1_1| x2_0| x3_0|     phi.value(4)  |
  +-----+-----+-----+-------------------+
  | x1_1| x2_0| x3_1|     phi.value(5)  |
  +-----+-----+-----+-------------------+
  | x1_1| x2_1| x3_0|     phi.value(6)  |
  +-----+-----+-----+-------------------+
  | x1_1| x2_1| x3_1|     phi.value(7)  |
  +-----+-----+-----+-------------------+
  
  Parameters
  ----------
  variables: list, array-like
      List of variables on which the factor is to be defined i.e. scope of the factor.
  
  cardinality: list, array_like
      List of cardinalities/no.of states of each variable. `cardinality`
      array must have a value corresponding to each variable in
      `variables`.
  
  values: list, array_like
      List of values of factor.
      A DiscreteFactor's values are stored in a row vector in the value
      using an ordering such that the left-most variables as defined in
      `variables` cycle through their values the fastest. Please refer
      to examples for usage examples.
  
  Examples
  --------
  >>> import numpy as np
  >>> from pgmpy.factors.discrete import DiscreteFactor
  >>> phi = DiscreteFactor(['x1', 'x2', 'x3'], [2, 2, 2], np.ones(8))
  >>> phi
  <DiscreteFactor representing phi(x1:2, x2:2, x3:2) at 0x7f8188fcaa90>
  >>> print(phi)
  +------+------+------+-----------------+
  | x1   | x2   | x3   |   phi(x1,x2,x3) |
  |------+------+------+-----------------|
  | x1_0 | x2_0 | x3_0 |          1.0000 |
  | x1_0 | x2_0 | x3_1 |          1.0000 |
  | x1_0 | x2_1 | x3_0 |          1.0000 |
  | x1_0 | x2_1 | x3_1 |          1.0000 |
  | x1_1 | x2_0 | x3_0 |          1.0000 |
  | x1_1 | x2_0 | x3_1 |          1.0000 |
  | x1_1 | x2_1 | x3_0 |          1.0000 |
  | x1_1 | x2_1 | x3_1 |          1.0000 |
  +------+------+------+-----------------+
class_docstr_tok: ["Initialize","a","`","DiscreteFactor","`","class",".","Defined","above",",","we","have","the","following","mapping","from","variable","assignments","to","the","index","of","the","row","vector","in","the","value","field",":","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1","|","x2","|","x3","|","phi","(","x1",",","x2",",","x3",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1_0|","x2_0|","x3_0|","phi.value","(","0",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1_0|","x2_0|","x3_1|","phi.value","(","1",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1_0|","x2_1|","x3_0|","phi.value","(","2",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1_0|","x2_1|","x3_1|","phi.value","(","3",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1_1|","x2_0|","x3_0|","phi.value","(","4",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1_1|","x2_0|","x3_1|","phi.value","(","5",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1_1|","x2_1|","x3_0|","phi.value","(","6",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","|","x1_1|","x2_1|","x3_1|","phi.value","(","7",")","|","+","--","--","-+","--","--","-+","--","--","-+","--","--","--","--","--","--","--","--","--","-+","Parameters","--","--","--","--","--","variables",":","list",",","array-like","List","of","variables","on","which","the","factor","is","to","be","defined","i.e",".","scope","of","the","factor",".","cardinality",":","list",",","array_like","List","of","cardinalities\/no.of","states","of","each","variable",".","`","cardinality","`","array","must","have","a","value","corresponding","to","each","variable","in","`","variables","`",".","values",":","list",",","array_like","List","of","values","of","factor",".","A","DiscreteFactor","'s","values","are","stored","in","a","row","vector","in","the","value","using","an","ordering","such","that","the","left-most","variables","as","defined","in","`","variables","`","cycle","through","their","values","the","fastest",".","Please","refer","to","examples","for","usage","examples",".","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","from","pgmpy.factors.discrete","import","DiscreteFactor",">",">",">","phi","=","DiscreteFactor","(","[","'x1","'",",","'x2","'",",","'x3","'","]",",","[","2",",","2",",","2","]",",","np.ones","(","8",")",")",">",">",">","phi","<","DiscreteFactor","representing","phi","(","x1:2",",","x2:2",",","x3:2",")","at","0x7f8188fcaa90",">",">",">",">","print","(","phi",")","+","--","--","--","+","--","--","--","+","--","--","--","+","--","--","--","--","--","--","--","--","-+","|","x1","|","x2","|","x3","|","phi","(","x1",",","x2",",","x3",")","|","|","--","--","--","+","--","--","--","+","--","--","--","+","--","--","--","--","--","--","--","--","-|","|","x1_0","|","x2_0","|","x3_0","|","1.0000","|","|","x1_0","|","x2_0","|","x3_1","|","1.0000","|","|","x1_0","|","x2_1","|","x3_0","|","1.0000","|","|","x1_0","|","x2_1","|","x3_1","|","1.0000","|","|","x1_1","|","x2_0","|","x3_0","|","1.0000","|","|","x1_1","|","x2_0","|","x3_1","|","1.0000","|","|","x1_1","|","x2_1","|","x3_0","|","1.0000","|","|","x1_1","|","x2_1","|","x3_1","|","1.0000","|","+","--","--","--","+","--","--","--","+","--","--","--","+","--","--","--","--","--","--","--","--","-+"]
docstr: DiscreteFactor division by `phi1`.
  
  Parameters
  ----------
  phi1 : `DiscreteFactor` instance
      The denominator for division.
  
  inplace: boolean
      If inplace=True it will modify the factor itself, else would return
      a new factor.
  
  Returns
  -------
  Divided factor: pgmpy.factors.discrete.DiscreteFactor or None
      If inplace=True (default) returns None else returns a new `DiscreteFactor` instance.
  
  Examples
  --------
  >>> from pgmpy.factors.discrete import DiscreteFactor
  >>> phi1 = DiscreteFactor(['x1', 'x2', 'x3'], [2, 3, 2], range(12))
  >>> phi2 = DiscreteFactor(['x3', 'x1'], [2, 2], range(1, 5))
  >>> phi1.divide(phi2)
  >>> phi1.variables
  ['x1', 'x2', 'x3']
  >>> phi1.cardinality
  array([2, 3, 2])
  >>> phi1.values
  array([[[ 0.        ,  0.33333333],
          [ 2.        ,  1.        ],
          [ 4.        ,  1.66666667]],
         [[ 3.        ,  1.75      ],
          [ 4.        ,  2.25      ],
          [ 5.        ,  2.75      ]]])
docstr_tok: ["DiscreteFactor","division","by","`","phi1","`",".","Parameters","--","--","--","--","--","phi1",":","`","DiscreteFactor","`","instance","The","denominator","for","division",".","inplace",":","boolean","If","inplace=True","it","will","modify","the","factor","itself",",","else","would","return","a","new","factor",".","Returns","--","--","--","-","Divided","factor",":","pgmpy.factors.discrete.DiscreteFactor","or","None","If","inplace=True","(","default",")","returns","None","else","returns","a","new","`","DiscreteFactor","`","instance",".","Examples","--","--","--","--",">",">",">","from","pgmpy.factors.discrete","import","DiscreteFactor",">",">",">","phi1","=","DiscreteFactor","(","[","'x1","'",",","'x2","'",",","'x3","'","]",",","[","2",",","3",",","2","]",",","range","(","12",")",")",">",">",">","phi2","=","DiscreteFactor","(","[","'x3","'",",","'x1","'","]",",","[","2",",","2","]",",","range","(","1",",","5",")",")",">",">",">","phi1.divide","(","phi2",")",">",">",">","phi1.variables","[","'x1","'",",","'x2","'",",","'x3","'","]",">",">",">","phi1.cardinality","array","(","[","2",",","3",",","2","]",")",">",">",">","phi1.values","array","(","[","[","[","0.",",","0.33333333","]",",","[","2.",",","1",".","]",",","[","4.",",","1.66666667","]","]",",","[","[","3.",",","1.75","]",",","[","4.",",","2.25","]",",","[","5.",",","2.75","]","]","]",")"]
code: def divide(self, phi1, inplace=True):
      """
      DiscreteFactor division by `phi1`.
  
      Parameters
      ----------
      phi1 : `DiscreteFactor` instance
          The denominator for division.
  
      inplace: boolean
          If inplace=True it will modify the factor itself, else would return
          a new factor.
  
      Returns
      -------
      Divided factor: pgmpy.factors.discrete.DiscreteFactor or None
          If inplace=True (default) returns None else returns a new `DiscreteFactor` instance.
  
      Examples
      --------
      >>> from pgmpy.factors.discrete import DiscreteFactor
      >>> phi1 = DiscreteFactor(['x1', 'x2', 'x3'], [2, 3, 2], range(12))
      >>> phi2 = DiscreteFactor(['x3', 'x1'], [2, 2], range(1, 5))
      >>> phi1.divide(phi2)
      >>> phi1.variables
      ['x1', 'x2', 'x3']
      >>> phi1.cardinality
      array([2, 3, 2])
      >>> phi1.values
      array([[[ 0.        ,  0.33333333],
              [ 2.        ,  1.        ],
              [ 4.        ,  1.66666667]],
             [[ 3.        ,  1.75      ],
              [ 4.        ,  2.25      ],
              [ 5.        ,  2.75      ]]])
      """
      phi = self if inplace else self.copy()
      phi1 = phi1.copy()
  
      if set(phi1.variables) - set(phi.variables):
          raise ValueError(
              "Scope of divisor should be a subset of dividend"
          )
  
      # Adding extra variables in phi1.
      extra_vars = set(phi.variables) - set(phi1.variables)
      if extra_vars:
          slice_ = [slice(None)] * len(phi1.variables)
          slice_.extend([np.newaxis] * len(extra_vars))
          phi1.values = phi1.values[tuple(slice_)]
  
          phi1.variables.extend(extra_vars)
  
      # Rearranging the axes of phi1 to match phi
      for axis in range(phi.values.ndim):
          exchange_index = phi1.variables.index(phi.variables[axis])
          phi1.variables[axis], phi1.variables[exchange_index] = (
              phi1.variables[exchange_index],
              phi1.variables[axis],
          )
          phi1.values = phi1.values.swapaxes(axis, exchange_index)
  
      phi.values = phi.values / phi1.values
  
      # If factor division 0/0 = 0 but is undefined for x/0. In pgmpy we are using
      # np.inf to represent x/0 cases.
      phi.values[config.get_compute_backend().isnan(phi.values)] = 0
  
      if not inplace:
          return phi
  
imports: from collections import namedtuple
  from itertools import product
  import numpy
  import pandas
  import torch
  from pgmpy import config
  from pgmpy.extern import tabulate
  from pgmpy.factors.base import BaseFactor
  from pgmpy.global_vars import logger
  from pgmpy.utils import StateNameMixin, compat_fns
label_desc: Use image node_id 14 for calling the DiscreteFactor obj's underlying member method code with example usage: obj.divide(phi1, inplace) and returns: phi