Python自动化脚本:高效实现CSV到Little_R格式的批量转换

news2026/4/4 12:49:25
1. 为什么需要CSV到Little_R格式的转换在日常数据处理工作中我们经常会遇到需要将数据从一种格式转换为另一种格式的需求。特别是对于气象研究人员和数据工程师来说CSV和Little_R这两种格式的转换尤为常见。CSVComma-Separated Values是最常见的数据交换格式之一它以纯文本形式存储表格数据用逗号分隔不同的字段。而Little_R格式则是气象领域常用的数据格式它使用空格作为字段分隔符并且有特定的数据排列要求。我曾在处理气象观测数据时就遇到过这样的需求气象站提供的原始数据都是CSV格式但我们的分析工具只接受Little_R格式。手动转换不仅耗时耗力还容易出错。这时候一个简单的Python脚本就能帮我们自动化完成这个繁琐的过程。2. 环境准备与基础概念2.1 Python环境配置在开始编写转换脚本之前我们需要确保Python环境已经正确配置。我推荐使用Python 3.6或更高版本因为这个脚本会用到一些较新的语法特性。如果你还没有安装Python可以从官网下载安装包。安装完成后建议创建一个专门的虚拟环境来管理项目依赖python -m venv csv_converter source csv_converter/bin/activate # Linux/Mac csv_converter\Scripts\activate # Windows2.2 理解CSV和Little_R格式的区别CSV格式大家都很熟悉它最大的特点就是用逗号分隔字段。比如2023-01-01,15.6,75,1013.2 2023-01-02,16.2,72,1012.8而Little_R格式则使用空格作为分隔符并且对数据的排列有严格要求2023-01-01 15.6 75 1013.2 2023-01-02 16.2 72 1012.8在实际转换过程中我们不仅需要替换分隔符还需要确保数据顺序和格式符合Little_R的要求。有些气象数据可能还需要添加特定的元数据头信息。3. 基础转换脚本编写3.1 单文件转换实现让我们从一个最简单的转换脚本开始。这个脚本可以处理单个CSV文件将其转换为Little_R格式def convert_csv_to_little_r(input_file, output_file): 将单个CSV文件转换为Little_R格式 :param input_file: 输入CSV文件路径 :param output_file: 输出Little_R文件路径 with open(input_file, r) as csv_file, open(output_file, w) as little_r_file: for line in csv_file: # 替换逗号为空格并去除可能的额外空格 converted_line line.replace(,, ).strip() \n little_r_file.write(converted_line) print(f成功转换文件: {input_file} - {output_file}) # 使用示例 convert_csv_to_little_r(input.csv, output.little_r)这个基础版本虽然简单但已经能够处理大多数基本的转换需求。不过在实际应用中我们通常需要处理更复杂的情况比如处理包含标题行的CSV文件处理带有引号的字段处理科学计数法表示的数字处理缺失值3.2 处理复杂CSV文件对于更复杂的CSV文件我们可以使用Python内置的csv模块它能更好地处理各种特殊情况import csv def advanced_conversion(input_file, output_file): with open(input_file, r) as csv_file, open(output_file, w) as little_r_file: reader csv.reader(csv_file) for row in reader: # 将每行数据用空格连接并确保格式正确 converted_line .join(row) \n little_r_file.write(converted_line) print(f高级转换完成: {input_file} - {output_file})这个版本可以正确处理包含逗号的引用字段比如New York, NY这样的城市名称。4. 批量转换实现4.1 处理整个文件夹的CSV文件在实际工作中我们往往需要处理成百上千个CSV文件。这时候批量转换功能就非常必要了。下面是一个完整的批量转换脚本import os import csv def batch_convert_csv_to_little_r(input_folder, output_folder): 批量转换文件夹中的所有CSV文件为Little_R格式 :param input_folder: 包含CSV文件的输入文件夹 :param output_folder: 输出文件夹路径 # 确保输出文件夹存在 os.makedirs(output_folder, exist_okTrue) # 统计转换文件数 converted_count 0 # 遍历输入文件夹中的所有文件 for filename in os.listdir(input_folder): if filename.lower().endswith(.csv): # 构建完整文件路径 input_path os.path.join(input_folder, filename) output_path os.path.join(output_folder, f{os.path.splitext(filename)[0]}.little_r) # 执行转换 try: with open(input_path, r) as csv_file, \ open(output_path, w) as little_r_file: reader csv.reader(csv_file) for row in reader: converted_line .join(row) \n little_r_file.write(converted_line) converted_count 1 print(f成功转换: {filename}) except Exception as e: print(f转换{filename}时出错: {str(e)}) print(f\n转换完成! 共处理了{converted_count}个文件) # 使用示例 batch_convert_csv_to_little_r(data/csv_files, data/little_r_files)4.2 添加进度显示和错误处理为了让脚本更加健壮和用户友好我们可以添加进度显示和更完善的错误处理import os import csv import sys def robust_batch_conversion(input_folder, output_folder): 更健壮的批量转换实现带有进度显示和详细错误处理 # 获取所有CSV文件 try: all_files [f for f in os.listdir(input_folder) if f.lower().endswith(.csv)] except OSError as e: print(f无法读取输入文件夹: {str(e)}) return total_files len(all_files) if total_files 0: print(输入文件夹中没有找到CSV文件) return # 准备输出文件夹 try: os.makedirs(output_folder, exist_okTrue) except OSError as e: print(f无法创建输出文件夹: {str(e)}) return # 开始转换 success_count 0 for i, filename in enumerate(all_files, 1): input_path os.path.join(input_folder, filename) output_path os.path.join(output_folder, f{os.path.splitext(filename)[0]}.little_r) # 显示进度 sys.stdout.write(f\r处理中: {i}/{total_files} ({filename})) sys.stdout.flush() try: with open(input_path, r) as csv_file, \ open(output_path, w) as little_r_file: reader csv.reader(csv_file) for row in reader: # 跳过空行 if not row: continue # 处理每行数据 converted_line .join(str(field).strip() for field in row) \n little_r_file.write(converted_line) success_count 1 except Exception as e: print(f\n处理{filename}时出错: {str(e)}) print(f\n\n转换完成! 成功处理{success_count}/{total_files}个文件) if success_count total_files: print(f有{total_files - success_count}个文件转换失败)这个版本添加了详细的错误处理和进度显示更适合处理大量文件的实际场景。5. 高级功能与优化5.1 添加元数据头信息Little_R格式通常需要包含特定的元数据头信息。我们可以扩展脚本自动添加这些信息def add_metadata_header(input_file, output_file, metadata): 转换CSV文件并添加Little_R元数据头 :param metadata: 字典形式的元数据 with open(input_file, r) as csv_file, \ open(output_file, w) as little_r_file: # 写入元数据头 for key, value in metadata.items(): little_r_file.write(f{key} {value}\n) # 写入分隔行 little_r_file.write(# DATA START\n) # 转换并写入数据 reader csv.reader(csv_file) for row in reader: if row: # 跳过空行 converted_line .join(str(field).strip() for field in row) \n little_r_file.write(converted_line) # 使用示例 metadata { station_id: WX12345, latitude: 39.9042, longitude: 116.4074, elevation: 43.5, data_source: 自动气象站 } add_metadata_header(data.csv, output.little_r, metadata)5.2 性能优化技巧当处理非常大的CSV文件时我们可以采用一些性能优化技巧使用生成器避免一次性加载整个文件到内存批量写入减少IO操作次数多线程处理对于多核CPU可以并行处理多个文件下面是一个优化后的版本import csv from concurrent.futures import ThreadPoolExecutor def optimized_conversion(input_folder, output_folder, batch_size1000): 优化性能的批量转换实现 :param batch_size: 批量写入的行数 def process_file(filename): input_path os.path.join(input_folder, filename) output_path os.path.join(output_folder, f{os.path.splitext(filename)[0]}.little_r) try: with open(input_path, r) as csv_file, \ open(output_path, w) as little_r_file: reader csv.reader(csv_file) buffer [] for row in reader: if row: converted_line .join(str(field).strip() for field in row) \n buffer.append(converted_line) # 批量写入 if len(buffer) batch_size: little_r_file.writelines(buffer) buffer [] # 写入剩余数据 if buffer: little_r_file.writelines(buffer) return filename, True except Exception as e: return filename, str(e) # 获取所有CSV文件 all_files [f for f in os.listdir(input_folder) if f.lower().endswith(.csv)] # 使用线程池并行处理 with ThreadPoolExecutor() as executor: results list(executor.map(process_file, all_files)) # 统计结果 success sum(1 for _, status in results if status is True) failures [(f, e) for f, e in results if status is not True] print(f处理完成! 成功: {success}, 失败: {len(failures)}) if failures: print(\n失败文件列表:) for f, e in failures: print(f- {f}: {e})6. 实际应用案例6.1 气象数据处理实例假设我们有一组气象站收集的CSV格式数据需要转换为Little_R格式供WRF模式使用。数据包含以下字段时间戳 (YYYY-MM-DD HH:MM:SS)温度 (°C)相对湿度 (%)气压 (hPa)风速 (m/s)风向 (度)我们可以编写专门的转换函数来处理这种特定格式def convert_weather_data(input_file, output_file, station_info): 转换气象站CSV数据为Little_R格式 :param station_info: 气象站信息字典 with open(input_file, r) as csv_file, \ open(output_file, w) as little_r_file: # 写入站点元数据 little_r_file.write( fstation_id {station_info[id]}\n fstation_name {station_info[name]}\n flatitude {station_info[lat]}\n flongitude {station_info[lon]}\n felevation {station_info[elev]}\n missing_value -9999\n # DATA START\n ) reader csv.reader(csv_file) for row in reader: if len(row) 6: # 确保有足够字段 try: timestamp row[0] temp float(row[1]) rh float(row[2]) pressure float(row[3]) wind_speed float(row[4]) wind_dir float(row[5]) # 格式化输出行 converted_line ( f{timestamp} {temp:.1f} {rh:.1f} f{pressure:.1f} {wind_speed:.1f} {wind_dir:.1f}\n ) little_r_file.write(converted_line) except ValueError as e: print(f忽略无效数据行: {row} (错误: {str(e)}))6.2 自动化工作流集成在实际项目中我们通常需要将这个转换过程集成到更大的数据处理工作流中。比如我们可以创建一个完整的处理管道从FTP服务器下载原始CSV文件验证数据完整性转换为Little_R格式质量检查上传到数据库或模型输入目录下面是一个简化的自动化工作流示例import paramiko # 用于SFTP传输 class WeatherDataProcessor: def __init__(self, config): self.config config def download_files(self): 从远程服务器下载CSV文件 transport paramiko.Transport((self.config[ftp_host], 22)) transport.connect(usernameself.config[ftp_user], passwordself.config[ftp_pass]) sftp paramiko.SFTPClient.from_transport(transport) try: for remote_file in sftp.listdir(self.config[remote_dir]): if remote_file.lower().endswith(.csv): local_path os.path.join(self.config[local_csv_dir], remote_file) sftp.get(os.path.join(self.config[remote_dir], remote_file), local_path) print(f下载完成: {remote_file}) finally: sftp.close() transport.close() def process_files(self): 处理所有下载的CSV文件 if not os.path.exists(self.config[local_littler_dir]): os.makedirs(self.config[local_littler_dir]) for filename in os.listdir(self.config[local_csv_dir]): if filename.lower().endswith(.csv): input_path os.path.join(self.config[local_csv_dir], filename) output_path os.path.join(self.config[local_littler_dir], f{os.path.splitext(filename)[0]}.little_r) convert_weather_data(input_path, output_path, self.config[station]) print(f处理完成: {filename}) def run(self): 执行完整工作流 print(开始下载文件...) self.download_files() print(\n开始处理文件...) self.process_files() print(\n所有处理完成!) # 配置示例 config { ftp_host: weather-data.example.com, ftp_user: user123, ftp_pass: password123, remote_dir: /incoming/csv, local_csv_dir: ./data/csv, local_littler_dir: ./data/little_r, station: { id: WX12345, name: Beijing Observatory, lat: 39.9042, lon: 116.4074, elev: 43.5 } } # 执行处理 processor WeatherDataProcessor(config) processor.run()7. 常见问题与解决方案7.1 编码问题处理在实际使用中经常会遇到CSV文件编码不一致的问题。特别是当处理来自不同来源的数据时可能会遇到UTF-8、GBK、ISO-8859-1等各种编码。我们可以改进脚本来自动检测和处理不同编码import chardet def detect_encoding(file_path): 检测文件编码 with open(file_path, rb) as f: raw_data f.read(1024) # 读取前1KB用于检测 result chardet.detect(raw_data) return result[encoding] def convert_with_encoding_handling(input_file, output_file): 处理不同编码的CSV文件 try: # 检测文件编码 encoding detect_encoding(input_file) with open(input_file, r, encodingencoding) as csv_file, \ open(output_file, w, encodingutf-8) as little_r_file: reader csv.reader(csv_file) for row in reader: if row: converted_line .join(str(field).strip() for field in row) \n little_r_file.write(converted_line) print(f成功转换: {input_file} (编码: {encoding})) return True except UnicodeDecodeError: print(f编码检测失败: {input_file}, 尝试其他编码...) # 尝试常见编码 for enc in [gbk, iso-8859-1, utf-16]: try: with open(input_file, r, encodingenc) as csv_file, \ open(output_file, w, encodingutf-8) as little_r_file: reader csv.reader(csv_file) for row in reader: if row: converted_line .join(str(field).strip() for field in row) \n little_r_file.write(converted_line) print(f使用备用编码 {enc} 成功转换: {input_file}) return True except: continue print(f无法确定文件编码: {input_file}) return False7.2 处理不规则CSV文件不是所有的CSV文件都遵循标准格式。我们可能会遇到包含注释行以#开头字段中包含换行符不规则的分隔符分号、制表符等混合引号风格下面是一个更健壮的CSV读取函数可以处理这些不规则情况def robust_csv_reader(csv_file): 处理不规则的CSV文件 for line in csv_file: # 跳过注释行和空行 if line.strip().startswith(#) or not line.strip(): continue # 处理字段中的换行符 while line.count() % 2 ! 0: # 引号不成对 next_line next(csv_file) line line.rstrip(\n) next_line # 使用csv模块解析处理后的行 try: row next(csv.reader([line])) yield row except csv.Error as e: print(f解析行时出错: {line.strip()} (错误: {str(e)})) continue def convert_irregular_csv(input_file, output_file): 转换不规则的CSV文件 encoding detect_encoding(input_file) with open(input_file, r, encodingencoding) as csv_file, \ open(output_file, w, encodingutf-8) as little_r_file: for row in robust_csv_reader(csv_file): if row: converted_line .join(str(field).strip() for field in row) \n little_r_file.write(converted_line) print(f不规则文件转换完成: {input_file})8. 脚本的进一步扩展8.1 添加命令行界面为了让脚本更易于使用我们可以添加命令行参数支持import argparse def main(): parser argparse.ArgumentParser( description批量转换CSV文件到Little_R格式) parser.add_argument(input, help输入文件或文件夹路径) parser.add_argument(output, help输出文件夹路径) parser.add_argument(--encoding, defaultauto, help指定文件编码 (默认: 自动检测)) parser.add_argument(--batch-size, typeint, default1000, help批量写入行数 (默认: 1000)) parser.add_argument(--threads, typeint, default4, help并行处理线程数 (默认: 4)) args parser.parse_args() # 检查输入路径 if os.path.isfile(args.input): # 单文件转换 if args.encoding auto: convert_with_encoding_handling(args.input, os.path.join(args.output, f{os.path.splitext(os.path.basename(args.input))[0]}.little_r)) else: convert_single_file(args.input, os.path.join(args.output, f{os.path.splitext(os.path.basename(args.input))[0]}.little_r), args.encoding) elif os.path.isdir(args.input): # 批量转换 batch_convert(args.input, args.output, args.encoding, args.batch_size, args.threads) else: print(f错误: 输入路径 {args.input} 不存在) sys.exit(1) if __name__ __main__: main()8.2 创建GUI界面对于不熟悉命令行的用户我们可以使用PySimpleGUI创建一个简单的图形界面import PySimpleGUI as sg def create_gui(): layout [ [sg.Text(输入文件夹:), sg.Input(), sg.FolderBrowse()], [sg.Text(输出文件夹:), sg.Input(), sg.FolderBrowse()], [sg.Checkbox(包含子文件夹, defaultTrue)], [sg.Checkbox(覆盖已存在文件, defaultFalse)], [sg.Combo([自动检测, UTF-8, GBK, ISO-8859-1], default_value自动检测, key-ENCODING-)], [sg.Button(开始转换), sg.Button(退出)], [sg.Output(size(80, 20))] ] window sg.Window(CSV到Little_R转换工具, layout) while True: event, values window.read() if event in (sg.WINDOW_CLOSED, 退出): break elif event 开始转换: input_folder values[0] output_folder values[1] include_subfolders values[2] overwrite values[3] encoding values[-ENCODING-] if values[-ENCODING-] ! 自动检测 else auto if not input_folder or not output_folder: sg.popup_error(请选择输入和输出文件夹!) continue print(f开始转换: {input_folder} - {output_folder}) print(f参数: 编码{encoding}, 包含子文件夹{include_subfolders}, 覆盖{overwrite}) # 这里调用实际的转换函数 try: batch_convert(input_folder, output_folder, encoding, include_subfolders, overwrite) sg.popup(转换完成!) except Exception as e: sg.popup_error(f转换出错: {str(e)}) window.close() if __name__ __main__: create_gui()这个GUI界面提供了基本的文件选择功能和转换选项使得工具对非技术用户也更加友好。9. 测试与验证9.1 编写单元测试为了确保转换脚本的可靠性我们应该编写单元测试来验证各种情况import unittest import tempfile import os import shutil class TestCSVToLittleR(unittest.TestCase): def setUp(self): # 创建临时文件夹 self.test_dir tempfile.mkdtemp() self.input_dir os.path.join(self.test_dir, input) self.output_dir os.path.join(self.test_dir, output) os.makedirs(self.input_dir) os.makedirs(self.output_dir) # 创建测试CSV文件 self.simple_csv os.path.join(self.input_dir, simple.csv) with open(self.simple_csv, w, encodingutf-8) as f: f.write(date,temp,humidity\n) f.write(2023-01-01,15.6,75\n) f.write(2023-01-02,16.2,72\n) # 创建不规则CSV文件 self.irregular_csv os.path.join(self.input_dir, irregular.csv) with open(self.irregular_csv, w, encodingutf-8) as f: f.write(# 这是注释行\n) f.write(date;temp;humidity\n) # 使用分号分隔 f.write(2023-01-01;15.6;75\n) f.write(2023-01-02;16.2;72\n) def tearDown(self): # 清理临时文件夹 shutil.rmtree(self.test_dir) def test_simple_conversion(self): output_file os.path.join(self.output_dir, simple.little_r) convert_single_file(self.simple_csv, output_file) with open(output_file, r, encodingutf-8) as f: content f.readlines() self.assertEqual(len(content), 2) self.assertEqual(content[0].strip(), 2023-01-01 15.6 75) def test_batch_conversion(self): batch_convert(self.input_dir, self.output_dir) expected_files { simple.little_r, irregular.little_r } actual_files set(os.listdir(self.output_dir)) self.assertTrue(expected_files.issubset(actual_files)) def test_encoding_detection(self): # 创建GBK编码文件 gbk_csv os.path.join(self.input_dir, gbk.csv) with open(gbk_csv, w, encodinggbk) as f: f.write(日期,温度,湿度\n) f.write(2023-01-01,15.6,75\n) output_file os.path.join(self.output_dir, gbk.little_r) convert_with_encoding_handling(gbk_csv, output_file) self.assertTrue(os.path.exists(output_file)) if __name__ __main__: unittest.main()9.2 性能测试与优化建议在处理大量数据时性能可能成为瓶颈。我们可以进行一些性能测试并提出优化建议import time import random import pandas as pd def generate_large_csv(file_path, rows100000): 生成大型测试CSV文件 data { timestamp: pd.date_range(2023-01-01, periodsrows, freqH), temperature: [random.uniform(10, 30) for _ in range(rows)], humidity: [random.uniform(30, 90) for _ in range(rows)], pressure: [random.uniform(980, 1040) for _ in range(rows)] } df pd.DataFrame(data) df.to_csv(file_path, indexFalse) def performance_test(): 性能测试 # 准备测试文件 large_csv os.path.join(self.test_dir, large.csv) generate_large_csv(large_csv, rows100000) # 测试基础版本 start time.time() output_file os.path.join(self.output_dir, large_basic.little_r) convert_single_file(large_csv, output_file) basic_time time.time() - start # 测试优化版本 start time.time() output_file os.path.join(self.output_dir, large_optimized.little_r) optimized_conversion(large_csv, output_file, batch_size10000) optimized_time time.time() - start print(f\n性能测试结果 (100,000行):) print(f- 基础版本: {basic_time:.2f}秒) print(f- 优化版本: {optimized_time:.2f}秒) print(f- 性能提升: {(basic_time - optimized_time)/basic_time*100:.1f}%) # 内存使用建议 print(\n内存使用建议:) print(- 对于超过1GB的CSV文件考虑使用pandas的chunksize参数分块读取) print(- 可以使用Dask库处理超大型数据集) print(- 对于持续的数据流考虑使用生成器逐行处理)通过这样的性能测试我们可以了解不同实现方式的效率差异并根据实际需求选择合适的方案。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2482264.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SpringBoot-17-MyBatis动态SQL标签之常用标签

文章目录 1 代码1.1 实体User.java1.2 接口UserMapper.java1.3 映射UserMapper.xml1.3.1 标签if1.3.2 标签if和where1.3.3 标签choose和when和otherwise1.4 UserController.java2 常用动态SQL标签2.1 标签set2.1.1 UserMapper.java2.1.2 UserMapper.xml2.1.3 UserController.ja…

wordpress后台更新后 前端没变化的解决方法

使用siteground主机的wordpress网站,会出现更新了网站内容和修改了php模板文件、js文件、css文件、图片文件后,网站没有变化的情况。 不熟悉siteground主机的新手,遇到这个问题,就很抓狂,明明是哪都没操作错误&#x…

网络编程(Modbus进阶)

思维导图 Modbus RTU(先学一点理论) 概念 Modbus RTU 是工业自动化领域 最广泛应用的串行通信协议,由 Modicon 公司(现施耐德电气)于 1979 年推出。它以 高效率、强健性、易实现的特点成为工业控制系统的通信标准。 包…

UE5 学习系列(二)用户操作界面及介绍

这篇博客是 UE5 学习系列博客的第二篇,在第一篇的基础上展开这篇内容。博客参考的 B 站视频资料和第一篇的链接如下: 【Note】:如果你已经完成安装等操作,可以只执行第一篇博客中 2. 新建一个空白游戏项目 章节操作,重…

IDEA运行Tomcat出现乱码问题解决汇总

最近正值期末周,有很多同学在写期末Java web作业时,运行tomcat出现乱码问题,经过多次解决与研究,我做了如下整理: 原因: IDEA本身编码与tomcat的编码与Windows编码不同导致,Windows 系统控制台…

利用最小二乘法找圆心和半径

#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …

使用docker在3台服务器上搭建基于redis 6.x的一主两从三台均是哨兵模式

一、环境及版本说明 如果服务器已经安装了docker,则忽略此步骤,如果没有安装,则可以按照一下方式安装: 1. 在线安装(有互联网环境): 请看我这篇文章 传送阵>> 点我查看 2. 离线安装(内网环境):请看我这篇文章 传送阵>> 点我查看 说明&#xff1a;假设每台服务器已…

XML Group端口详解

在XML数据映射过程中&#xff0c;经常需要对数据进行分组聚合操作。例如&#xff0c;当处理包含多个物料明细的XML文件时&#xff0c;可能需要将相同物料号的明细归为一组&#xff0c;或对相同物料号的数量进行求和计算。传统实现方式通常需要编写脚本代码&#xff0c;增加了开…

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器的上位机配置操作说明

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器专为工业环境精心打造&#xff0c;完美适配AGV和无人叉车。同时&#xff0c;集成以太网与语音合成技术&#xff0c;为各类高级系统&#xff08;如MES、调度系统、库位管理、立库等&#xff09;提供高效便捷的语音交互体验。 L…

(LeetCode 每日一题) 3442. 奇偶频次间的最大差值 I (哈希、字符串)

题目&#xff1a;3442. 奇偶频次间的最大差值 I 思路 &#xff1a;哈希&#xff0c;时间复杂度0(n)。 用哈希表来记录每个字符串中字符的分布情况&#xff0c;哈希表这里用数组即可实现。 C版本&#xff1a; class Solution { public:int maxDifference(string s) {int a[26]…

【大模型RAG】拍照搜题技术架构速览:三层管道、两级检索、兜底大模型

摘要 拍照搜题系统采用“三层管道&#xff08;多模态 OCR → 语义检索 → 答案渲染&#xff09;、两级检索&#xff08;倒排 BM25 向量 HNSW&#xff09;并以大语言模型兜底”的整体框架&#xff1a; 多模态 OCR 层 将题目图片经过超分、去噪、倾斜校正后&#xff0c;分别用…

【Axure高保真原型】引导弹窗

今天和大家中分享引导弹窗的原型模板&#xff0c;载入页面后&#xff0c;会显示引导弹窗&#xff0c;适用于引导用户使用页面&#xff0c;点击完成后&#xff0c;会显示下一个引导弹窗&#xff0c;直至最后一个引导弹窗完成后进入首页。具体效果可以点击下方视频观看或打开下方…

接口测试中缓存处理策略

在接口测试中&#xff0c;缓存处理策略是一个关键环节&#xff0c;直接影响测试结果的准确性和可靠性。合理的缓存处理策略能够确保测试环境的一致性&#xff0c;避免因缓存数据导致的测试偏差。以下是接口测试中常见的缓存处理策略及其详细说明&#xff1a; 一、缓存处理的核…

龙虎榜——20250610

上证指数放量收阴线&#xff0c;个股多数下跌&#xff0c;盘中受消息影响大幅波动。 深证指数放量收阴线形成顶分型&#xff0c;指数短线有调整的需求&#xff0c;大概需要一两天。 2025年6月10日龙虎榜行业方向分析 1. 金融科技 代表标的&#xff1a;御银股份、雄帝科技 驱动…

观成科技:隐蔽隧道工具Ligolo-ng加密流量分析

1.工具介绍 Ligolo-ng是一款由go编写的高效隧道工具&#xff0c;该工具基于TUN接口实现其功能&#xff0c;利用反向TCP/TLS连接建立一条隐蔽的通信信道&#xff0c;支持使用Let’s Encrypt自动生成证书。Ligolo-ng的通信隐蔽性体现在其支持多种连接方式&#xff0c;适应复杂网…

铭豹扩展坞 USB转网口 突然无法识别解决方法

当 USB 转网口扩展坞在一台笔记本上无法识别,但在其他电脑上正常工作时,问题通常出在笔记本自身或其与扩展坞的兼容性上。以下是系统化的定位思路和排查步骤,帮助你快速找到故障原因: 背景: 一个M-pard(铭豹)扩展坞的网卡突然无法识别了,扩展出来的三个USB接口正常。…

未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?

编辑&#xff1a;陈萍萍的公主一点人工一点智能 未来机器人的大脑&#xff1a;如何用神经网络模拟器实现更智能的决策&#xff1f;RWM通过双自回归机制有效解决了复合误差、部分可观测性和随机动力学等关键挑战&#xff0c;在不依赖领域特定归纳偏见的条件下实现了卓越的预测准…

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …

华为云AI开发平台ModelArts

华为云ModelArts&#xff1a;重塑AI开发流程的“智能引擎”与“创新加速器”&#xff01; 在人工智能浪潮席卷全球的2025年&#xff0c;企业拥抱AI的意愿空前高涨&#xff0c;但技术门槛高、流程复杂、资源投入巨大的现实&#xff0c;却让许多创新构想止步于实验室。数据科学家…

深度学习在微纳光子学中的应用

深度学习在微纳光子学中的主要应用方向 深度学习与微纳光子学的结合主要集中在以下几个方向&#xff1a; 逆向设计 通过神经网络快速预测微纳结构的光学响应&#xff0c;替代传统耗时的数值模拟方法。例如设计超表面、光子晶体等结构。 特征提取与优化 从复杂的光学数据中自…