You can use exp(x) function of math library, which is same as e^x. Hence you may write your code as:

import math
x.append(1 - math.exp( -0.5 * (value1*value2)**2))

I have modified the equation by replacing 1/2 as 0.5. Else for Python <2.7, we'll have to explicitly type cast the division value to float because Python round of the result of division of two int as integer. For example: 1/2 gives 0 in python 2.7 and below.

Answer from Moinuddin Quadri on Stack Overflow
🌐
Homehost
homehost.com.br › início › python ext:pdf – extensões pdf no python
Python ext:pdf - extensões PDF no Python | Homehost
September 10, 2023 - As bibliotecas de extensões PDF no Python (ext:pdf) permitem trabalhar com arquivos PDF. Dessa forma, permite não apenas ler e escrever arquivos PDF, mas também manipular seus conteúdos, como adicionar, remover e alterar páginas, campos ...
🌐
Boston University
bu.edu › lernet › artemis › years › 2011 › slides › python.pdf pdf
python.pdf
E.g. Print: ... Hello world! ... Hello world ! ... Helloworld! ... Hello world ! ... Not a String? Not a Problem! ... The value of x is 42 .
🌐
Experts Exchange
experts-exchange.com › articles › 40764 › Using-Python-to-automatically-fill-PDFs.html
Using Python to automatically fill PDFs | Experts Exchange
5 hours ago - exactly the same in the excel spreadsheet and the PDF. Once I had done this, the script generated the files as one would expect, filling in all the fields. Used: Platform: Windows 11 laptop Program: Microsoft Visual Studio Code (VS Code) Python: 3.13.x Required PDF form: Student Recommendation Form - blank.pdf Required spreadsheet: students-blank.csv Python script file (listed above): fill_form.py If you found this article helpful, please do not hesitate to give it a thumbs up.
🌐
CodeConvert AI
codeconvert.ai › python-to-pdf
Python to PDF Generator
This free online code to PDF converter lets you convert your Python code to a beautifully formatted PDF document with syntax highlighting.
🌐
University of the Basque Country
cfm.ehu.es › ricardo › docs › python › Learning_Python.pdf pdf
Learning Python
B. Solutions to End-of-Part Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1101 · Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1139 ... This book provides an introduction to the Python programming language.
Top answer
1 of 1
1

The range of available solutions for Python-related PDF tools, modules, and libraries is a bit confusing, and it takes a moment to figure out what is what, and which projects are maintained continuously. Based on our research these are the candidates that are up-to-date:

PyPDF2: A Python library to extract document information and content, split documents page-by-page, merge documents, crop pages, and add watermarks. PyPDF2 supports both unencrypted and encrypted documents.

PDFMiner: Is written entirely in Python, and works well for Python 2.4. For Python 3, use the cloned package PDFMiner.six. Both packages allow you to parse, analyze, and convert PDF documents. This includes the support for PDF 1.7 as well as CJK languages (Chinese, Japanese, and Korean), and various font types (Type1, TrueType, Type3, and CID).

PDFQuery: It describes itself as "a fast and friendly PDF scraping library" which is implemented as a wrapper around PDFMiner, lxml, and pyquery. Its design aim is "to reliably extract data from sets of PDFs with as little code as possible."

tabula-py: It is a simple Python wrapper of tabula-java, which can read tables from PDFs and convert them into Pandas DataFrames. It also enables you to convert a PDF file into a CSV/TSV/JSON file.

pdflib for Python: An extension of the Poppler Library that offers Python bindings for it. It allows you to parse, analyze, and convert PDF documents. Not to be confused with its commercial pendant that has the same name.

PyFPDF: A library for PDF document generation under Python. Ported from the FPDF PHP library, a well-known PDFlib-extension replacement with many examples, scripts, and derivatives.

PDFTables: A commercial service that offers extraction from tables that comes as a PDF document. Offers an API so that PDFTables can be used as SAAS.

PyX - the Python graphics package: PyX is a Python package for the creation of PostScript, PDF, and SVG files. It combines an abstraction of the PostScript drawing model with a TeX/LaTeX interface. Complex tasks like creating 2D and 3D plots in publication-ready quality are built out of these primitives.

ReportLab: An ambitious, industrial-strength library largely focused on precise creation of PDF documents. Available freely as an Open Source version as well as a commercial, enhanced version named ReportLab PLUS.

PyMuPDF (aka "fitz"): Python bindings for MuPDF, which is a lightweight PDF and XPS viewer. The library can access files in PDF, XPS, OpenXPS, epub, comic and fiction book formats, and it is known for its top performance and high rendering quality.

pdfrw: A pure Python-based PDF parser to read and write PDF. It faithfully reproduces vector formats without rasterization. In conjunction with ReportLab, it helps to re-use portions of existing PDFs in new PDFs created with ReportLab.

Find elsewhere
Top answer
1 of 1
1

I don't know if the exponential curve math is accurate in this code, but it certainly isn't the slow point.

First, you read the input data in one read call. It does have to be read, but that loads the entire file. The next step takes the first line only, so it would seem more appropriate to use readline. That split itself is O(n) where n is the file size, at least, which might include data you were ignoring since you only process one line.

Second, you convert that line into an int. This probably requires Python's long integer support, but the operation could be O(n) or O(n^2). A single pass algorithm would multiply the accumulated number by 10 for each digit, allocating one or two new (longer) longs each time.

Third, sum_digits breaks that long int down into digits again. It does so using division, which is expensive, and two operations as well, rather than using divmod. That's O(n^2), because each division has to process every higher digit for each digit. And it's only needed because of the conversion you just did.

Summing the digits found in a string is likely easier done with something like sum(int(c) for c in l if c.isdigit()) where l is the input line. It's not particularly fast, as there's quite a bit of overhead in the digit conversions and the sum might grow large, but it does make a single pass with a fairly tight loop; it's somewhere between O(n) and O(n log n), depending on the length of the data, because the sum might grow large itself.

As for the unknown exponential curve, the existence of an exception for a low number is concerning. There's likely some other option that's both faster and more accurate if the answer's an integer anyway.

Lastly, you have at least four distinct output data formats: error, 2, 3.0, 3e+20. Do you know which of these is expected? Perhaps you should be using formatted output rather than str to convert your numbers.

One extra note: If the data is really large, processing it in chunks will definitely speed things up (instead of running out of memory, needing to swap, etc). As you're looking for a digit sum your size complexity can be reduced from O(n) to O(log n).

🌐
Real Python
realpython.com › creating-modifying-pdf
Create and Modify PDF Files in Python – Real Python
January 19, 2025 - In this tutorial, you'll explore the different ways of creating and modifying PDF files in Python. You'll learn how to read and extract text, merge and concatenate files, crop and rotate pages, encrypt and decrypt files, and even create PDFs from scratch.
🌐
W3Schools
w3schools.com › python › ref_math_exp.asp
Python math.exp() Method
'E' is the base of the natural system of logarithms (approximately 2.718282) and x is the number passed to it. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-math-library-exp-method
Python math library | exp() method - GeeksforGeeks
February 7, 2023 - # Python3 code to demonstrate # the working of exp() import math # checking for string print (math.exp("25"))
🌐
Medium
medium.com › @wandrys.sousa › python-x-pdf-pypdf2-is-old-use-pypdf-when-working-with-pdf-in-python-7b32f4664bb4
[Python x PDF] PyPDF2 is old! Use pypdf when working with PDF in Python | by Wandrys Nascimento | Medium
April 23, 2023 - To do this let’s first save the pdf The External Balance Assessment Methodology: 2018 Update ( https://www.imf.org/-/media/Files/Publications/WP/2019/WPIEA2019065.ashx) If all goes well the pdf will be saved as WPIEA2019065.pdf · Now let’s get to the code! # import modules import os from pypdf import PdfReader from PIL import Image # Import PDF #Please change the directory path reader = PdfReader(r"C:\xxxxxxx\PyPDF\WPIEA2019065.pdf") # Get pages.
🌐
CoolUtils
coolutils.com › online › py to pdf
Convert PY to PDF Online for Free | CoolUtils
Need to send or archive a Python script without worrying about editors or line endings? This online PY-to-PDF converter turns .py files into tidy, paginated PDF documents—perfect for code reviews, legal handoffs, coursework, and documentation.
Rating: 4.9 ​ - ​ 1.64K votes
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.exp.html
numpy.exp — NumPy v2.1 Manual
The irrational number e is also known as Euler’s number. It is approximately 2.718281, and is the base of the natural logarithm, ln (this means that, if \(x = \ln y = \log_e y\), then \(e^x = y\).
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.exp.html
numpy.exp — NumPy v2.4 Manual
The irrational number e is also known as Euler’s number. It is approximately 2.718281, and is the base of the natural logarithm, ln (this means that, if \(x = \ln y = \log_e y\), then \(e^x = y\).
🌐
Dr-chuck
do1.dr-chuck.com › pythonlearn › EN_us › pythonlearn.pdf pdf
Python for Everybody Exploring Data Using Python 3 Dr. Charles R. Severance
You can also extract the right-most digit or digits from a number. For example, x % 10 yields the right-most digit of x (in base 10).
🌐
Note.nkmk.me
note.nkmk.me › home › python
Power and Logarithmic Functions in Python: exp, log, log10, log2 | note.nkmk.me
August 10, 2023 - math - Power and logarithmic functions — Mathematical functions — Python 3.11.4 documentation ... All sample code in this article assumes that the math module has been imported. ... Euler's number, also known as Napier's constant, is provided as a constant in the math module and is represented by math.e.
🌐
GitHub
github.com › py-pdf › pypdf
GitHub - py-pdf/pypdf: A pure-python PDF library capable of splitting, merging, cropping, and transforming the pages of PDF files
pypdf is a free and open-source pure-python PDF library capable of splitting, merging, cropping, and transforming the pages of PDF files. It can also add custom data, viewing options, and passwords to PDF files.
Starred by 9.8K users
Forked by 1.6K users
Languages   Python