From ef1f0522f449aa91bcaa45cdd40aafa250d70385 Mon Sep 17 00:00:00 2001 From: guanjihuan Date: Thu, 10 Jul 2025 16:33:55 +0800 Subject: [PATCH] update --- .../common/example_of_loop_calculation.py | 33 +++++++++++++++++++ .../common/example_of_try_except.py | 10 +++--- 2 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 2024.01.16_GUAN_package_learning/common/example_of_loop_calculation.py diff --git a/2024.01.16_GUAN_package_learning/common/example_of_loop_calculation.py b/2024.01.16_GUAN_package_learning/common/example_of_loop_calculation.py new file mode 100644 index 0000000..40b598e --- /dev/null +++ b/2024.01.16_GUAN_package_learning/common/example_of_loop_calculation.py @@ -0,0 +1,33 @@ +# 循环参数计算 + +import guan +import numpy as np + +def test_1(x): + return 2*x + +x_array = np.arange(0, 5, 1) +result_array = guan.loop_calculation_with_one_parameter(test_1, x_array) +print(result_array) +guan.plot(x_array, result_array) +print() + +def test_2(x, y): + return x+y + +x_array = np.arange(0, 5, 1) +y_array = np.arange(0, 3, 1) +result_array = guan.loop_calculation_with_two_parameters(test_2, x_array, y_array) +print(result_array) +guan.plot_contour(x_array, y_array, result_array) +print() + +def test_3(x, y, z): + return x+y+z + +x_array = np.arange(0, 5, 1) +y_array = np.arange(0, 3, 1) +z_array = np.arange(0, 2, 1) +result_array = guan.loop_calculation_with_three_parameters(test_3, x_array, y_array, z_array) +print(result_array) +guan.plot_contour(y_array, z_array, result_array[:, :, 4]) \ No newline at end of file diff --git a/2024.01.16_GUAN_package_learning/common/example_of_try_except.py b/2024.01.16_GUAN_package_learning/common/example_of_try_except.py index 899a713..5f7f423 100644 --- a/2024.01.16_GUAN_package_learning/common/example_of_try_except.py +++ b/2024.01.16_GUAN_package_learning/common/example_of_try_except.py @@ -1,22 +1,22 @@ import guan +@guan.try_decorator def test1(a, b): print(a) bug_code print(b) return 'return_message1' - -result1 = guan.try_except(test1, 10, b=20) + +result1 = test1(10, b=20) print(result1) print() -@guan.try_decorator def test2(a, b): print(a) bug_code print(b) return 'return_message2' - -result2 = test2(100, b=200) + +result2 = guan.try_except(test2, 100, b=200) print(result2) \ No newline at end of file