def write_matrix_to_tsv(net, filename=None, df=None):
    """
  This will export the matrix in net.dat or a dataframe (optional df in
  arguments) as a tsv file. Row/column categories will be saved as tuples in
  tsv, which can be read back into the network object.
  """
    import pandas as pd
    if df is None:
        df = net.dat_to_df()
    return df['mat'].to_csv(filename, sep='\t')
