在Python中读取数字通常有以下几种方法:
直接读取字符串并转换
```python
s = input("请输入数字:")
a, b = map(int, s.split()), map(int, s.split())
使用正则表达式
```python
import re
filename = "example.txt"
numbers = [int(x) for x in re.findall(r'\d+', filename)]
从图像中读取数字 (使用OCR库如Tesseract):
```python
from PIL import Image
import pytesseract
image = Image.open('image.jpg')
text = pytesseract.image_to_string(image)
numbers = [int(x) for x in text.split() if x.isdigit()]
从文件中读取数字
```python
with open('data.txt', 'r') as file:
lines = file.readlines()
numbers = [list(map(float, line.strip().split())) for line in lines]
使用Pandas读取CSV文件
```python
import pandas as pd
data = pd.read_csv('/path/to/data.csv', header=None)
numbers = data.values.flatten().tolist()
使用NumPy读取数组文件
```python
import numpy as np
data = np.loadtxt('data.dat')
请根据您的具体需求选择合适的方法。