339 questions from the last 7 days
9
votes
1
answer
172
views
Generating blue noise with values sampled from a log normal distribution
Aim
I am trying to generate random signals with the following two properties:
The values should be approximately log-normally distributed (any long-tailed distribution bounded form below with non-...
0
votes
2
answers
90
views
Creating list of Dictionaries from .csv, mixed datatypes issue
I have imported a .csv and turned it into a list of dictionaries with the headings as the keys. However my values are a mix of string, int, float, and True/False.
Is there an easy way to have these ...
4
votes
1
answer
124
views
Identifying outliers from openCV contours based on curvature?
I'm processing a photo of the Earth from the Moon, as seen here.
What I want to do is get the contour points that correspond to the edge of the Earth that is not in shadow. (e.g., the areas that ...
2
votes
2
answers
65
views
Data class with argument optional only in init
I have the following simple class in Python:
class Point:
def __init__(x: int, y: int | None = None):
self.x = x
self.y = y if y is not None else x
How can the same thing be ...
3
votes
1
answer
83
views
Python3 dictionary being modified at another thread does not show changes after those modifications at the original thread [closed]
Python version: (3.9, but the same result with python 3.12)
The goal was that another thread modified a dictionary and those modifications to be available at the original thread.
import ...
-1
votes
2
answers
101
views
What is the difference between xpath() and findall()?
Very often I see that calls to xpath could as well be replaced by calls to findall, when can this be done? What is the main differences between the two functions?
The first argument to path findall ...
4
votes
3
answers
125
views
NumPy broadcasting error when trying to add 2D array and 1D array
I'm trying to perform an element-wise addition between a 2D NumPy array and a 1D array (like adding a row vector to each row of a matrix), but I'm running into a broadcasting error.
import numpy as np
...
1
vote
1
answer
104
views
Calculate Exponential decay rate constant from graph
I would like to calculate the lifetime of the particles from the extrapolated curve below, I know that lifetime is 1/decay constant but I get values for the decay constant that dont make sense.
import ...
0
votes
2
answers
119
views
Print only assert message in Python
Is there any way print only assert message:
assert 5==4, "test"
will print:
Traceback (most recent call last):
File "C:\Users\user\temp\test.py", line 4, in <module>
...
2
votes
3
answers
110
views
How can I execute a Python script in the REPL interpreter mode and get the exactly same output as if it was manually typed in? (Ubuntu, Python 3.12)
The Python interpreter can be run either in script or interactive/REPL mode.
I do have a Python script as text file but want to run it as if it was manually typed in in the interactive/REPL mode.
I ...
0
votes
1
answer
90
views
How to identify contours using OpenCV or traditional methods?
Background: I currently have many grayscale images of steel. Some of them have high brightness, while others have uneven brightness. As shown in the figure below, how can I better extract their ...
3
votes
1
answer
70
views
How can I add secondary 'y' and 'x' axis to this contour?
I have been trying to set up secondary 'y' and 'x' axes on the filled contour plot using matplotlib. My goal is to have additional 'x' and 'y' axis such that both are function of the values of their ...
4
votes
2
answers
106
views
How do I compute group means in a pandas DataFrame when grouped by ranking?
What I'd like to do is create a DataFrame with dates as indices, ranks as columns, and values pulled from scores. Since the ranking method guarantees uniqueness, I suppose I can melt/dropna/pivot to ...
1
vote
2
answers
105
views
playwright python how to detect browser window is closed
I'm writing a simple Python script using requests.get to scrape data from a website that requires login. The script first checks whether the user is already logged in. If not, it launches a Chromium ...
3
votes
2
answers
57
views
I trying to generate Erdös-Rényi Random Graphs faster with python using threading, but it didn't work, maybe I am doing something wrong?
This is the code I'm using, it take around 15-16 seconds to print the graph. I was also trying to make the threads uniquely giving for every a name and starting and join using that name, but no matter ...