Skip to content

Commit 29c6f0f

Browse files
authored
perf: use np.sum to compute sum (#122)
1 parent 0686a18 commit 29c6f0f

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

pdftotree/utils/pdf/pdf_parsers.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from functools import cmp_to_key
1414
from typing import Any, Dict, List, Tuple
1515

16+
import numpy as np
1617
from pdfminer.layout import LTFigure, LTTextLine
1718
from pdfminer.utils import Plane
1819

@@ -1274,11 +1275,8 @@ def get_page_width(boxes):
12741275

12751276

12761277
def get_char_width(boxes: List[LTTextLine]) -> float:
1277-
box_len_sum = 0
1278-
num_char_sum = 0
1279-
for i, b in enumerate(boxes):
1280-
box_len_sum = box_len_sum + b.bbox[2] - b.bbox[0]
1281-
num_char_sum = num_char_sum + len(b.get_text())
1278+
box_len_sum = np.sum([b.bbox[2] - b.bbox[0] for b in boxes])
1279+
num_char_sum = np.sum([len(b.get_text()) for b in boxes])
12821280
try:
12831281
return box_len_sum / num_char_sum
12841282
except ZeroDivisionError:

0 commit comments

Comments
 (0)