Skip to main content

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
3 votes
0 answers
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 ...
mq7's user avatar
  • 131
2 votes
0 answers
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 ...
openspace's user avatar
  • 151
2 votes
0 answers
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 ...
Imen Z Imanou's user avatar
2 votes
0 answers
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 ...
Yoav's user avatar
  • 21
2 votes
0 answers
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. ...
nalzok's user avatar
  • 1,101
2 votes
0 answers
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 ...
singularli's user avatar
2 votes
0 answers
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 ...
Rami Luisto's user avatar
2 votes
0 answers
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 ...
Kamor04's user avatar
  • 121
1 vote
1 answer
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: ...
FaisalShakeel's user avatar
1 vote
0 answers
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 ...
Nau's user avatar
  • 111
1 vote
0 answers
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 ...
LateGameLank's user avatar
1 vote
2 answers
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). ...
river_bell's user avatar
1 vote
1 answer
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 ...
G-Shillcock's user avatar
1 vote
1 answer
40 views

Finding all zero sums of length m and checking for zero subsums on an abelian group (generalization of the sub sum problem?)

Let $G$ be an abelian group. We say that $G$ has property $V_n$ if for every $m > n$ and a list $L\subset G$ of $m$ elements s.t. $\sum_{g\in L}g=0$ there is a proper subset $\emptyset\neq L'\...
levav ferber tas's user avatar
1 vote
0 answers
43 views

Long and short memory in reinforcement learning Connect 4 AI

I'm writing an AI based on reinforcement learning to play Connect 4. That's my second bot and attempt to RNN and AI (first was copy a code of snake RNN AI from youtube) and I'm looking for some ...
Saguro's user avatar
  • 11
1 vote
0 answers
29 views

What Data Structure works best for this problem?

I have 2 sets of atmost 25000 4-tuples. Currently, I am storing them as 2 lists of 4-tuples A and B. I have to perform the following computation for each of the combinations of A and B. ...
WhiteShark's user avatar
1 vote
0 answers
34 views

Multimodal machine learning dataset fine tuning for binary classification problem

Hello i am new to machine learning, i am working on a multimodal dataset, basically memes dataset, The data consists of an image and an overlay text, i have no clue how to feed a model both of the ...
Mohamed Fouad's user avatar
1 vote
0 answers
133 views

Multiplication algorithm I wrote - slower than I expected

Recently I thought of an algorithm for multiplication and decided to stop dreaming and start writing on paper my ideas, and even implement this to code (in this case - Python 3.9.1). I do not know if ...
CSch of x's user avatar
1 vote
0 answers
69 views

Why does a kalman filter work better in a simulation than in real life?

I am trying to use a classical Kalman filter for getting indoor location. I am using geolocation API of HTML to get latitude, longitude, position accuracy and speed. I am also using the smartphone's ...
Dhanraj Mahurkar's user avatar
1 vote
0 answers
55 views

3D Reconstruction from multiview calibrated camera

I have a calibrated camera whose intrinsics were calculated prior. Suppose I have multi images with the same camera. Using the first two views.I have the 1) initial reconstruction using 8 point ...
Sara Ahmed's user avatar
1 vote
0 answers
29 views

What is the best algorithm for detecting the texture of a person's clothes in real-time for a mobile robot?

I am working on the human following robot. the robot extracts a feature of clothes's texture and distinguishes between the people that they stand up in front of the robot. So, the robot needs that it ...
Redhwan's user avatar
  • 111
1 vote
0 answers
53 views

Termination Character in Suffix Trees

I am trying to create a generalised suffix tree from a very large number of strings using Ukkonen's algorithm, however I run out of unique symbols to use as string termination characters. I was ...
PABLO's user avatar
  • 41
1 vote
0 answers
72 views

Can this graph-ordering problem be solved with LP?

I have a modelling problem that I am trying to solve with LP. (More specifically, in Python using PuLP or Pyomo). I am not terribly knowledgeable in this area and have been struggling to find the ...
biddlesby's user avatar
  • 123
1 vote
0 answers
53 views

How to implement minimization of maximum regret?

We run a report, but for one of our big clients, it is taking too long. There is a loop where it loops for a list and fetches it upstream 1by1. We're making this a bulk operation now, but some items ...
Tjorriemorrie's user avatar
1 vote
0 answers
60 views

How to go about designing a quiz that changes difficulty based on user performance?

I thought about using a machine learning algorithm to learn the performance patterns of the quiz taker and model the next quiz based on how he/she performed. So each question will have a difficulty ...
Cogitabundus's user avatar
0 votes
1 answer
46 views

Coding the labyrinth solver

The question mathematically has been answered here: https://math.stackexchange.com/questions/4886084/guaranteed-graph-labyrinth-solving-sequence/4887473#4887473 To summarize, in an unknown strongly ...
user555076's user avatar
0 votes
1 answer
110 views

A floating-point rounding problem

I run the Python code below. x and y differ in their 4th and 5th number, and x has larger ...
Rocky's user avatar
  • 11
0 votes
0 answers
24 views

How do one decide topic for first data analysis project?

Suppose an absolute beginner (in the field of data analysis/data science), which is indeed my case, has decided to create a project for his/her resume. These are the skills he has learnt: Python(...
Swayam Jha's user avatar
0 votes
0 answers
8 views

Networks and Internet Systems

I'm currently preparing for a final exam in Networks and Internet Systems. I don't have a large background knowledge on the topics, so I'm attempting to use python to approach the majority of question ...
Kate's user avatar
  • 1
0 votes
0 answers
14 views

Identifying peaks at every cluster

I have a data set showing different clusters of data points and was attempting to find a way to get the peak of at every cluster. Comparing the moving average between a set of points does not work as ...
Nader's user avatar
  • 101
0 votes
0 answers
33 views

Trying to model HIV using cellular automaton but can't replicate the results of some paper

There is this paper in which HIV is modelled using cellular automaton. I am trying to replicate this work but I am not getting the same results as the authors. In this paper the authors describe the ...
Max's user avatar
  • 1
0 votes
1 answer
55 views

fast estimation of the amount of unique combinations

Let's say I have a set of two columns - Name, Surname. I have a list of possible values for Name -> Jacob, John Surname -> Mayerson, Kindle. I want to generate a set of unique combinations for ...
lapots's user avatar
  • 125
0 votes
2 answers
61 views

compute the intersection of two polytopes and it's corner points

I am looking for a method in python/matlab to calculate the corner points of polytope which is an intersection of a polytope with half spaces. I have a polytope P1 of the form -1<= x0 <= 1 -1&...
Möbius's user avatar
  • 21
0 votes
0 answers
43 views

Approach for the fake data generator that needs to maintain an order and referential integrity

I have a Python data generator capable of generating SQL-like relational data with primary and foreign key relationships, composite keys, and partial keys. Currently, I store this data in-memory using ...
lapots's user avatar
  • 125
0 votes
0 answers
91 views

A practical issue in the code of HackerRank Restaurant problem

Problem Statement Martha is interviewing at Subway. One of the rounds of the interview requires her to cut a bread of size $\ell \times b$ into smaller identical pieces such that each piece is a ...
Math-Learner's user avatar
0 votes
0 answers
98 views

Create a simple Neural Network of n layers in python from scratch with numpy to solve XOR example problem using Batch Gradient Descent

I'm a young programmer that was interested by machine learning. I watched videos and read articles about the theory behind simple neural networks. However, I can't manage to set it up correctly. I've ...
NolanGio's user avatar
0 votes
2 answers
104 views

Speeding up an array search for duplicate

I was tasked with writing a function that finds the value of an element that is the first duplicate in an array to be encountered. For the array [2, 1, 3, 5, 3, 2] ...
Lucky's user avatar
  • 101
0 votes
2 answers
1k views

Dynamic Programming - Difficult Jumping Frog Problem

Given a set of $n$ stones, arranged in a row at equal distances from each other. The stones are numbered from $0$ to $n-1$. A frog that is on stone number $0$ has to get to stone number $n-1$. A jump ...
PK96's user avatar
  • 71
0 votes
0 answers
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 ...
LEJP's user avatar
  • 1
0 votes
0 answers
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: ...
Hydra's user avatar
  • 1
0 votes
0 answers
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 ...
graphicart86's user avatar
0 votes
0 answers
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 ...
LLMM's user avatar
  • 1
0 votes
0 answers
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, ...
Cookie's user avatar
  • 101
0 votes
0 answers
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 ...
E2R0NS's user avatar
  • 101
0 votes
0 answers
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: ...
loko's user avatar
  • 1
0 votes
0 answers
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 ...
mnijhum's user avatar
0 votes
0 answers
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 ...
user11452926's user avatar
0 votes
0 answers
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 ...
ProgramHelp's user avatar
0 votes
0 answers
121 views

How to convert a string (number representation) to an arbitrary base using custom alphabet?

I'm trying to figure out an efficient way (without recursion) to convert a string (number representation) from one arbitrary base to another using custom alphabet. But I cannot think of a very fast ...
AlekseyHoffman's user avatar
0 votes
0 answers
50 views

How did we go from Binary to something like Python?

If there's one thing the pandemic has shown us its that High school Geometry did not save us. I am a high school math teacher and I understand my job and its usefulness only exist in a post scarcity ...
CSNOOB SAFE Space pls 's user avatar