2,207,540 questions
Best practices
0
votes
2
replies
22
views
(python) remove items from a list based on multiple criteria, without skipping
i have multiple lists of a bunch of strings gathered indiscriminately. i want to remove any that are unsuitable based on various criteria.
import re
asdf = ["apple", "dreamy", &...
0
votes
0
answers
17
views
How to subclass operator overloading in Python properly and keep Pylance happy? [closed]
I wanted the Python Fraction class to output mixed fractions. For example, I wanted str(Fraction(-7, 3)) to output '-2 1/3' not '-7/3'. So I implemented the following MixedFraction subclass:
from ...
Advice
0
votes
3
replies
82
views
Why does Python have `hash(-1) == hash(-2) == -2`?
I'm not sure how to really motivate this question, but in playing around with integer hashes in Python (3.14.3, but I imagine this has been the case for many versions), I noticed that for almost any ...
Advice
0
votes
4
replies
52
views
Obtaining root access in Python without elevating the rest of the script
I have a small Python script that requires a list of physical disks (not partitions or volumes) and their respective capacities. I'm using the pyparted module to accomplish this:
readable_disks_dict = ...
Advice
0
votes
0
replies
55
views
Large weather dataset design
I need to do some processing and analysis on a large dataset of weather and hydrological data. The data I'm scraping from the host website is formatted like this:
site_1 = [
['1970-01-01 00:00', -1.40,...
Advice
0
votes
3
replies
67
views
Undo last pop() in a Python stack implementation
I'm implementing a simple stack in Python and I want to add the ability to undo the last pop() operation.
The behavior I want is something like this:
s.push(10)
s.push(20)
s.push(30)
s.pop() # ...
0
votes
0
answers
44
views
How to robustly intercept PyTorch CUDA OOM in a Python subprocess and dynamically adjust batch_size within an autonomous AI Agent loop?
I am building an autonomous AI Agent (managing training workflows) that automatically generates PyTorch/OpenMMLab training scripts and executes them in a background subprocess.
One of the common ...
-1
votes
0
answers
53
views
CUDA Out of Memory (OOM) when fine-tuning MedGemma-9B with QLoRA on a single 24GB GPU
I am trying to fine-tune the MedGemma-9B model for a medical document auditing task. I am using a single RTX 4090 with 24GB of VRAM. However, I keep encountering a CUDA Out of Memory error right when ...
1
vote
1
answer
52
views
Why does Groq langchain model return 'tool use failed error'?
One of my Langchain tools returns the below error when the agent is invoked, and so the agent does not actually proceed after the program is run:
groq.BadRequestError: Error code: 400 - {'error': {'...
1
vote
0
answers
55
views
How can I speed up vertices showing and animation?
I made my own 3D render with Pygame and added basic .obj import, but even a teapot lags a lot because vertices 2d array's length is long. How can I optimize code as much as possible inside game loop?
...
2
votes
0
answers
35
views
Why is my `mapped_column` function not auto-completing when I pass `insert_default` as a parameter?
Why is my `mapped_column` function not auto-completing when I pass `insert_default` as a parameter? I'm using PyCharm as my IDE.
class base(DeclarativeBase):
create_time: Mapped[datetime] = ...
Advice
0
votes
2
replies
51
views
How to automatically convert scalar to numpy array?
I would like to know how to conveniently make sure that a scalar is automatically converted to a numpy array that can be indexed. Note that np.asarray(x) will not work, since if x is a scalar, np....
Best practices
0
votes
2
replies
31
views
Implementing HTMX in a Django app: Should I use two templates per view?
When trying to integrate HTMX into my Django app, I'm facing a design issue. My base.html file contains fixed layout elements (a navigation bar and a title). I created a container section with the ID #...
Advice
0
votes
5
replies
84
views
How do i fix the print code to give me the grades for 100 students instead of the 100th student
for i in range(1, 101):
score = random.randint(1, 100)
print(f"Student {i}: {score}")
if score >= 80:
grade = "A"
elif score >= 60:
grade = "B"
...
0
votes
0
answers
53
views
Fitting linear regression and computing metrics in python
I have two data series of model prediction and observations. I am able to make line plots of these series. I would like to add a linear regression fit of the two data series. i would also like to add ...