Tags: python regex

Where is such a regex wrong?

Tags: ,


I am using python. The pattern is: re.compile(r’^(.+?)-?.*?(.+?)’) The text like: text1 = ‘TVTP-S2(xxxx123123)’ text2 = ‘TVTP(xxxx123123)’ I expect to get TVTP

Python: Get single signal from ipywidgets.observe() rather than 3

Tags: , ,


Essentially, I am creating a number of Toggle Buttons using ipywidgets. When the button is clicked, I would like to add an element to a list. If the button is unclicked, the element is to be removed. (…

Insert a matrix in matplolib

Tags: , ,


I want to import a numpy matrix in a matplotlib plot. Let’s say that I have this matrix: [[ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9,10,11,12]] In a scale from 0 to 3 of the x axis, I want to plot the …

Convert 5D tensor to 4D tensor in PyTorch

Tags: , ,


In PyTorch I have a 5D tensor X of dimensions B x 9 x C x H x W. I want to convert it into a 4D tensor Y with dimensions B x 9C x H x W such that concatenation happens channel wise. To illustrate let, …

PySpark “illegal reflective access operation” when executed in terminal

Tags: , ,


I’ve installed Spark and components locally and I’m able to execute PySpark code in Jupyter, iPython and via spark-submit – however receiving the following WARNING’s: WARNING: An illegal reflective …

How to generate low character primary keys for NoSQL/DynamoDB?

Tags: , ,


I need to generate room codes for a Flask project, in a similar style to how https://jackbox.tv/ does it. These room codes will serve as the primary key in a DynamoDB table, and as such will need to …

Tags: pandas python

Replace apostrophes and curly brackets with blank space in multiple columns of dataframe

Tags: ,


I have a table (dataframe) where multiple string columns contain curly brackets and apostrophes, which I am trying to replace with a blank space: I started with the genre1 column but I keep getting a …

Detect rectangles in an image with Python

Tags: , , ,


I have a large collection of binary images like these ones: On each image I need to detect the white rectangle. The rectangles have different dimensions and orientations and sometimes they are …

Tags: json python

JSON JSONDecodeError: Extra data Python

Tags: ,


I’m trying to print every value of a Json using Python. There are 3 Json phrases that are seperated by “,” and I get an error if I try to load all of it to the json.loads function. Here is …

How to create a list from a dict of lists that has combinations of the array elements [closed]

Tags: , , ,


The question might have been worded confusingly so here I will try to make it more clear. Suppose I have a dict like x = {0: [(36, 44)], 1: [(38, 39), (38, 40), (39, 40)], 2: [(37, 41), (37, 42), (41, …