def create_stoichiometric_matrix(model, array_type='<STR_LIT>', dtype=None):
if array_type not in ('<STR_LIT>', '<STR_LIT>') and not dok_matrix:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if dtype is None:<EOL><INDENT>dtype = np.float64<EOL><DEDENT>array_constructor = {<EOL>'<STR_LIT>': np.zeros, '<STR_LIT>': dok_matrix, '<STR_LIT>': lil_matrix,<EOL>'<STR_LIT>': np.zeros,<EOL>}<EOL>n_metabolites = len(model.metabolites)<EOL>n_reactions = len(model.reactions)<EOL>array = array_constructor[array_type]((n_metabolites, n_reactions),<EOL>dtype=dtype)<EOL>m_ind = model.metabolites.index<EOL>r_ind = model.reactions.index<EOL>for reaction in model.reactions:<EOL><INDENT>for metabolite, stoich in iteritems(reaction.metabolites):<EOL><INDENT>array[m_ind(metabolite), r_ind(reaction)] = stoich<EOL><DEDENT><DEDENT>if array_type == '<STR_LIT>':<EOL><INDENT>metabolite_ids = [met.id for met in model.metabolites]<EOL>reaction_ids = [rxn.id for rxn in model.reactions]<EOL>return pd.DataFrame(array, index=metabolite_ids, columns=reaction_ids)<EOL><DEDENT>else:<EOL><INDENT>return array<EOL><DEDENT>
Return a stoichiometric array representation of the given model.

    The the columns represent the reactions and rows represent
    metabolites. S[i,j] therefore contains the quantity of metabolite `i`
    produced (negative for consumed) by reaction `j`.

    Parameters
    ----------
    model : cobra.Model
        The cobra model to construct the matrix for.
    array_type : string
        The type of array to construct. if 'dense', return a standard
        numpy.array, 'dok', or 'lil' will construct a sparse array using
        scipy of the corresponding type and 'DataFrame' will give a
        pandas `DataFrame` with metabolite indices and reaction columns
    dtype : data-type
        The desired data-type for the array. If not given, defaults to float.

    Returns
    -------
    matrix of class `dtype`
        The stoichiometric matrix for the given model.