import os
import numpy as np
from scipy.spatial.distance import cosine
import csv
# 获取文件夹中所有文件的键值对映射
def get_file_mapping(folder_path):
file_map = {}
for root, dirs, files in os.walk(folder_path):
for file in files:
file_map[file] = os.path.abspath(os.path.join(root, file))
return file_map
# 找到两个文件名的最长匹配长度
def find_max_common_prefix_length(file1, file2):
i = 0
while i < len(file1) and i < len(file2) and file1[i] == file2[i]:
i += 1
return i
# 找到文件夹a和文件夹b中匹配的文件
def find_matching_files(folder_a, folder_b):
a_map = get_file_mapping(folder_a)
b_map = get_file_mapping(folder_b)
matching_files = []
for file_a, path_a in a_map.items():
max_common_prefix_length = 0
matching_file_b = ""
for file_b, path_b in b_map.items():
common_prefix_length = find_max_common_prefix_length(file_a, file_b)
if common_prefix_length > max_common_prefix_length:
ma
如何递归对比两个文件夹当中npy文件的内容
最新推荐文章于 2025-07-19 15:50:40 发布
本文介绍了一个Python程序,用于在两个文件夹中查找具有最长共同前缀的Numpy文件,并比较它们的形状、数值差异和余弦相似度。

最低0.47元/天 解锁文章
792

被折叠的 条评论
为什么被折叠?



