# 调用你的函数读取.dat文件 def read_dat(file_path): with open(file_path, 'r') as f: lines = f.readlines() data = [] for line in lines: split_line = line.strip().split(',') label = split_line[0] image = np.fromstring(split_line[1], sep=' ') data.append((label, image)) return data
# 示例文件路径 file_path = 'example.dat' data = read_dat(file_path) print(data)