# Questions tagged [python]

Programming questions are off-topic here. Do not ask questions about how to write code in Python. However, conceptual questions about computer science are more appropriate. See our help center for the scope of this site.

69 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
39 views

### Subtype Check with Type DAG

Trying to understand how compiler/static-type-checker checks for subtyping, I run into 2 problems. 1. Reachability in DAG Since both Python/C++ support multiple inheriatnce, the types can be ...
• 131
32 views

### Fast calculations using fast-Fourier convolution

Consider an array $X$ with shape $H \times W$. Let $Y$ be the other array of the same shape and $Z$ is an array of shape $h \times w$. We want to construct an array $R$ of shape $(H-h + 1, W-w+ 1)$ by ...
• 151
130 views

### How to calculate delta Q (modularity increase matrix) in graphs?

I've been trying to implement the Three-stage Algorithm to compare its results with our new proposed algorithm with different datasets than those mentioned in the article. I've succeeded in ...
139 views

### How do you write a python\pseudo code that generates all pair permutations?

What would be a good pseudo code or Python 3 code for the following permutations problem? Let us define a n-permutation as a bijective function $\pi: \{0,...,n-1\}\rightarrow \{0,...,n-1\}$ and ...
• 21
65 views

### Reducing Kleene's predecessor for Church numerals

I am trying to "reinvent" Kleene's predecessor myself. The following code snippet should be self-explanatory. The idea is to make a 2-tuple and count up from zero, i.e. ...
• 1,101
79 views

### Consider vectorization and for loop, do both approaches have the same time complexity?

I am learning this post Fast computation of nearest neighbors is an active area of research in machine learning. The most naive neighbor search implementation involves the brute-force computation ...
392 views

### On teaching Kolmogorov complexity with Python and the complexity of composed strings

The setting of this question is a bit long-winded, but please bear with me. This fall I will be lecturing a course on mathematical information theory, and on a few lectures we will be discussing ...
• 121
1k views

### Knapsack problem in real life

My task is to develop an algorithm for the optimal arrangement of cylindrical objects in cartons. The algorithm is to have the task of placing as many products as possible into cartons, at the same ...
• 121
1 vote
20 views

### Generate product description from product specifications

I am looking for a python NLP library that can generate a proper product description based on product features provided to it. Till now, i have tried transformers library and this is the code: ...
1 vote
47 views

### How many different colors are possible to generate in the HSV Color Space using OpenCV?

I don't know if this post belongs in this site because I feel it might be a programming question, but also I feel it might be related to the way Color Spaces work, if it does't belong here I can ...
• 111
1 vote
27 views

### Auxiliary Space Complexity of Dictionaries whose Keys are Iterables of Variable Size

Recently, I began delving into complexity analysis with dictionaries. More specifically, I have been looking at auxiliary space complexity. For the most part, this type of analysis has been ...
1 vote
125 views

### Diffucuty in understanding code after a recursive call

This is an example algorithm of a recursive insertion sort I'm trying to understand. I've have tried understanding this with the help of print statements (which I've commented). ...
1 vote
116 views

### Sympy does not recognise when two partial derivatives happen to be equal

I am trying to find the first and second-order partial derivatives of a function of four variables $S$ using pythons symbolic math package sympy. The issue is that sympy does not automatically see ...
1 vote
40 views

• 71
228 views

### render = font.render(text, 1, (0, 0, 0)) pygame.error: Library not initialized

the error im receiving is : file "/home/lucas/python/cargame/utils.py", line 17, in blit_text_center render = font.render(text, 1, (0, 0, 0)) pygame.error: Library not initialized the ...
• 1
96 views

### Why is Python erasing all data in my text file?

I am having trouble understanding what's going on. I have just been introduced to the open() and close() commands in Python. I have a code that is very similar to the code below: ...
24 views

### Different results in standard deviation of test set and cross validation

I have used KNN for predicting the output power of solar panels. The results are shown below: Test Set: MAE = 0.044 MSE = 0.004 Standard Deviation = 0.272 ...
406 views

### Python closest subset sum function

I'm writing a closestSubset(s,A) function that takes an integer s and an array of positive integers A and returns an array consisting of elements of A which add up to s. If there is no subset that ...
• 1
123 views

### Efficient way to do self join with minimum support?

In the apriori algorithm there's the self join step, So, say we have 1 3 2 3 3 5 2 5 If I were to do an exhaustive join I'd end up with a tuple including (1, 3, ...
• 101
331 views

### Creating a database of math questions and of answers and a front end for them

Need some guidance on where to begin. I am just learning python if it has any bearing. I want to create a page on my site where users log in, choose multiple topics from a list, choose between levels ...
• 101
57 views

### Finding the longest repeating substring with suffix arrays

I found an implementation of suffix arrays here (not sure if it's the most efficient so if there's any better I'd be glad to know). For a given string: ...
• 1
33 views

### How to get best path from a set of path using Q-Learning?

I have 10 data sets (lat and long) of the same path. I started from point A and stopped in point B and did this 10 times for a single route to get the data. While collecting the data, there were some ...
92 views

### How to modify the following Dijkstra/ Uniform-cost search to return the result for all end points?

I know there is a lot of code out there that does this, but in particular, I'm trying to modify the following code to not just return the goal node/ one end point, but all endpoints. How do I go about ...
• 101
88 views

### Python program to output the smallest palindromic number above a given input

I am quite new to python. I want to create a Python program to output the smallest palindromic number above a given input. But this input can be up to 20 digits. I tried finding all the palindromic ...