From 1df542aaef9dbe49ec30ef3c67ce2ada682868e3 Mon Sep 17 00:00:00 2001 From: guanjihuan Date: Sat, 1 Mar 2025 22:01:26 +0800 Subject: [PATCH] 0.1.158 --- PyPI/setup.cfg | 2 +- PyPI/src/guan.egg-info/PKG-INFO | 2 +- PyPI/src/guan/file_reading_and_writing.py | 34 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/PyPI/setup.cfg b/PyPI/setup.cfg index ebf30bc..4cb6810 100644 --- a/PyPI/setup.cfg +++ b/PyPI/setup.cfg @@ -1,7 +1,7 @@ [metadata] # replace with your username: name = guan -version = 0.1.157 +version = 0.1.158 author = guanjihuan author_email = guanjihuan@163.com description = An open source python package diff --git a/PyPI/src/guan.egg-info/PKG-INFO b/PyPI/src/guan.egg-info/PKG-INFO index b6c1e66..e6e11bc 100644 --- a/PyPI/src/guan.egg-info/PKG-INFO +++ b/PyPI/src/guan.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.2 Name: guan -Version: 0.1.157 +Version: 0.1.158 Summary: An open source python package Home-page: https://py.guanjihuan.com Author: guanjihuan diff --git a/PyPI/src/guan/file_reading_and_writing.py b/PyPI/src/guan/file_reading_and_writing.py index 48fda9b..5a0c54f 100644 --- a/PyPI/src/guan/file_reading_and_writing.py +++ b/PyPI/src/guan/file_reading_and_writing.py @@ -243,6 +243,40 @@ def write_two_dimensional_data_without_xy_array_and_without_opening_file(matrix, f.write(str(element)+' ') f.write('\n') +# 把矩阵写入.md文件(Markdown表格形式) +def write_matrix_in_markdown_format(matrix, filename='a'): + import numpy as np + matrix = np.array(matrix) + dim_0 = matrix.shape[0] + dim_1 = matrix.shape[1] + with open(filename+'.md', 'w', encoding='UTF-8') as f: + for i1 in range(dim_1): + f.write(f'| column {i1+1} ') + f.write('|\n') + for i1 in range(dim_1): + f.write('| :---: ') + f.write('|\n') + for i0 in range(dim_0): + for i1 in range(dim_1): + f.write(f'| {matrix[i0, i1]} ') + f.write('|\n') + +# 把矩阵写入.md文件(Latex形式) +def write_matrix_in_latex_format(matrix, filename='a', format='bmatrix'): + import numpy as np + matrix = np.array(matrix) + dim_0 = matrix.shape[0] + dim_1 = matrix.shape[1] + with open(filename+'.md', 'w', encoding='UTF-8') as f: + f.write(f'$$\\begin{{{format}}}\n') + for i0 in range(dim_0): + for i1 in range(dim_1): + if i1 != dim_1-1: + f.write(f'{matrix[i0, i1]} & ') + else: + f.write(f'{matrix[i0, i1]} \\\\\n') + f.write(f'\\end{{{format}}}$$') + # 如果不存在文件夹,则新建文件夹 def make_directory(directory='./test'): import os