Questions tagged [python]
Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability. Use the python tag for all Python related questions. If you believe your question may be even more specific, you can include a version specific tag such as python-3.x.
15,548 questions
0
votes
0
answers
45
views
Element-wise natural logarithm of large array
Let X be a numpy.array of np.float32 with shape (100,100,100,100). I'm computing the variable lX with the following formula
<...
3
votes
2
answers
720
views
Retrieval-Augmented Generation from text files
Context: I'm a complete newbie trying to get good at structuring my code. I'm aware that I'm supposed to do my own research with docs, but I don't know what specific docs I should be reading for this ...
6
votes
2
answers
421
views
Get orientation of a contour according to the smallest side
Context: Based on the code we can find here, an API to control to control Niryo's robots pyniryo/vision/image_functions:l120.
Return orientation of a contour according to the smallest side in order ...
2
votes
0
answers
74
views
backward induction algorithm computation
Is there a way to significantly speed-up this code?
I'm solving a dynamic programming model using a backward induction algorithm. A crucial step is to calculate the current-period value function (VF), ...
9
votes
3
answers
1k
views
Command Line Hangman game
I've completed a Hangman game in Python and was wondering about the formatting of this code. There were several functions that I switched around while making this, and there were several times where I ...
9
votes
2
answers
311
views
Simple Node.js version manager v2
As a followup to my previous version, I decided to try make this more cross-platform. I considered several languages: C++ is pretty cross platform, Rust is gaining popularity (and the language used by ...
5
votes
2
answers
176
views
LeetCode Number 416: Partition Equal Subset Sum
Problem: MLE
I am confused as to why the LeetCode judge reports Memory Limit Exceeded when my solution looks close to the editorial solution. I not too familiar with ...
8
votes
4
answers
1k
views
Python Exception Monitor
I have built a data pipeline in Python (3.12). It typically processes hundreds of thousands of files and runs for several days. A particular pipeline function calls external web APIs that sometimes ...
4
votes
3
answers
152
views
Function to calculate energy where all parameters must be positive
I have a function which requires all parameters to be positive:
...
3
votes
1
answer
95
views
Time series prediction by LSTM model
I have a collection of TEC data. My data sample for example: day1, day2, day3, day4.
Case1:
I have the following task to do: Training by the consecutive 3 days to predict the each 4th day. Each day ...
1
vote
0
answers
97
views
Runtime function overloading / dynamic dispatch for Python (2nd revision)
Second revision of the original post: Function overloading / dynamic dispatch for Python
TL;DR:
Improved version of this library[^1] based on previous reviews and criticism. It provides runtime ...
7
votes
5
answers
1k
views
Prime number finder below the limit specified
Is this an optimal solution? I doubt it is. Can someone please critique my code?
...
2
votes
0
answers
134
views
How to make this arbitrary precision π calculator using Machin-like formula run faster?
Two days ago (or yesterday depending on your timezone) was π-day. So I thought it was a good day to calculate π.
I used Machin-like formula to calculate π, in homage of William Shanks, who calculated ...
6
votes
3
answers
392
views
Function which returns arithmetic expression based on an operator
For the following code, I have trouble improving it.
I need to write a function getExpression(level, operator) which has one integer parameter representing a level ...
4
votes
1
answer
62
views
IBM File Processing and PDF Conversion App Using PyQt6 and FPDF
I am trying to convert a 111MB TEXT file to PDF quickly. I'm currently using the FPDF library, and large files take about 40 minutes to process. The text file is an IBM carriage control (ANSI) file ...