From 086ea90244636148bfafdf69f47239086c7c0dd9 Mon Sep 17 00:00:00 2001 From: wzy <675163717@qq.com> Date: Mon, 14 Oct 2024 20:52:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20function.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- function.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/function.py b/function.py index 12891e2..b6402bf 100644 --- a/function.py +++ b/function.py @@ -108,8 +108,9 @@ def img_to_vector(filename): - np.array: 二值图像向量。 """ with open(filename, 'r') as f: - return np.array([int(char) for char in f.read().strip()]).reshape(1, -1) - + lines = f.readlines() + vector = np.array([int(char) for line in lines for char in line.strip() if char.isdigit()]) + return vector.reshape(1, -1) if __name__ == "__main__": # 以下代码可用于测试,可自行随意修改