# 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.

183 questions
Filter by
Sorted by
Tagged with
14 views

### Finding a Hamiltonian Cycle in a directed graph - graph problem

$N$ towns are given, which we can get to by passing through the northern and southern gates. If you enter a town through a gate, you have to use another gate to leave the town. The merchant would like ...
24 views

### Codechef problem LAPTOPREC [closed]

I just can't seem to figure out that why does my code fail for the problem LAPTOPREC ...
276 views

### Number of Inversions found in Selection sort vs Exchange sort

Exchange sort is similar to selection sort, just swaps "overly eagerly" instead of finding the minimum and doing only one swap. And the swaps affect how often the ...
15 views

### Time series classification using multiples multivariate multi-length timeseries

0 I would like to develop a time series classification algorithm to classify use a of parachute. My data consist of multiple recording files (around 5min at 100hz, length of the recording can vary) ...
85 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 ...
63 views

### Implementing Flajolet–Martin algorithm in Python

I am stuck on what to do. I am trying to create a simple implementation of the Flajolet–Martin algorithm using Python. The stream will be the contents of a text file and you will produce an ...
6 views

### Sensitivity analysis of Multi-Layer Perceptron Neural Networks

I have used Multi-Layer Perceptron Neural Networks to do a binary classification. Now I want to perform a sensitivity analysis. I am planning to follow a similar approach to this paper. In case the ...
50 views

### Is it faster to use Counting Sort to lexicographically sort characters in a word in Python?

Assuming I have very long words, is it worth it to use Counting Sort with its memory overhead to achieve linear time complexity? I wrote a Python function that sorts the characters in a given string ...
25 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 ...
112 views

### Using pre-,post-, and in-order indexes to find information about a Binary Search Tree

Recently I have been studying ways of traversing a BST (in python), and have collided with the terms pre-order, post-order and in-order. I believe that I understood the three terms pretty well, and ...
625 views

### Doubt about computing running time / time complexity of a function in Python

I am learning about time complexity now, and I am working with BST (Binary Search Trees). This question needs some context and this is a follow up post to this post. Basically, I would like to compute ...
54 views

### Which approach of mine for an algorithm upper bound is correct?

Say we have this algorithm in Python. ...
1 vote
59 views

### When to stop training a back propagation algorithm based on the MSE?

I have a fully connected neural network that consists of 3 inputs + bias, 4 neuron hidden layer, and 2 layer output, I am using the sigmoid activation function on the hidden layer only and use the ...
1 vote
24 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. ...
1 vote
43 views

### Find the spanning tree minimizing the backtracking in an unweighted graph

I am working with undirected unweighted graphs, and I am searching for an algorithm that gives me a spanning tree minimizing the number of moves to visit every nodes. For example, given this graph : ...
1 vote
10 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 ...
29 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: ...
1 vote
99 views

### Efficient sorting an array generated from random distribution

I need to sort an array of n real numbers that was randomly generated in this way: I have a given set of k closed intervals: [a1,b1],[a2,b2],...,[ak,bk] whose beginning and end are natural numbers. ...
66 views

### Creating a PDA that accepts the following language

Using automata-lib 5.0.0 (Python library), I need help creating a Python program that simulates a PDA that only accepts the following language: L = {a^m b^n | 0 ≤ m != n} If you could provide any ...
8 views

### How a model can handle removed nighttime data in future predictions?

I want to use machine learning models for predicting one day ahead output power. In this model, I would like to remove all nighttime data because they do not make sense in prediction, but the problem ...
19 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 ...
1 vote
56 views

### MAE greater than MSE - is it possible?

I have used KNN for predicting the output power of solar panels. I have done feature scaling based on normalization for all data points. The problem is that the MAE is equal to 0.08, and MSE is equal ...
1 vote
15 views

### Is it really impossible to use K-fold cross validation for time series data?

I would like to know if it is impossible to use K-fold cross-validation for time series of data. It has been discussed that it is not reasonable to predict past from future, but I think this does not ...
1 vote
36 views

### Machine learning and test split for time series data

I have used different machine learning algorithms to predict solar panels' power output. There are ten independent features for weather data. In all models, I set time as an index and have used the ...
95 views

### Is Python truly OOP?

My understanding is that a programming language is generally paradigm (functional, procedural, OOP) independent: we can code using different paradigms in some language. However, some languages, like ...
23 views

### Scale a vector until it reaches a certain bound

I got a two points A and B with their respective x and y coordinates. Point B determines the direction of the vector AB, and I know that -10^9 <= x,y <= 10^9. ...
445 views

### What are the fundamentals of calculating space complexity in loops?

Imagine you loop n times, and every iteration you create a string of space n with scope only within that iteration (thus it is no longer accessible in the next iteration). I would look and say that I ...
37 views

### Complexities of algorithm for generating strings of length k from CNF grammar

Question: For the code "generate_language_rec" below, explain whether the time and space complexities are Linear, Polynomial or Exponential ( find a tight upper-bound ) in $k$. Assume the ...
91 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 ...
106 views

### Warnsdorff's rule: more errors with odd sized boards

I wrote an algorithm based on the Warnsdorff's rule to solve the knight's tour problem, where you need to create a sequence of moves of a knight on a chessboard such that the knight visits every ...
38 views

### Expected value of the remainder when a random variable is divided by a number

Let $a,b,c,d,e,f$ be integers selected from the set $\{1,2,\cdots, 100\}$ uniformly and at random with replacement. Let $M=a+2b+4c+8d+16e+32f$. What is the expected value of the remainder when $M$ is ...
31 views

### Why does python's threading library use OS level threads when it can't achieve parallelism?

I was surprised to hear that the threading module from python uses OS level threads. From what I know, OS level threads are more expensive (but can achieve parallelism) meanwhile green threads are ...
33 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, ...
87 views

### Python: Assigning values to 2D-array elements

I created a 2x2 2D-array of 0's as follows: sizes=[*2]*2 sizes [[0, 0], [0, 0]] I want to change the second element of the first row to 1. I do this as follows:...
27 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 ...
1 vote
63 views

### Why don't we recognize Python as a compiler-based language?

I just read this Why doesn't Python need a compiler? I know that Python isn't absolutely compiler or interpreted but it is both of them it's maybe an interpretive, high-level, and all-purpose ...
9 views

### Hand Landmark Coordinate Neural Network Not Converging

I'm currently trying to train a custom model with tensorflow to detect 17 landmarks/keypoints on each of 2 hands shown in an image (fingertips, first knuckles, bottom knuckles, wrist, and palm), for ...
14 views

### what do i need to consider writing a python script that uses a pre-trained model with new incoming data

I have completed and saved(with joblib) a trained model to do with detecting messages that exerts pressure. I understand that for me to use the model I would need to use joblib again to deploy my ...
1 vote
38 views

### What is the Big-O Time Complexity of this code?

I was wondering if someone could please explain what the time complexity is for the code below. I think it would be $O(n)$ because the algorithm will take as much time to execute as there are elements ...
53 views

### I made bubble_sort() function following the algorithm. But it is not working. where is my error? [closed]

This was the algorithm for bubble sort in textbook. I tried the with WHILE loop, then I tried the same with the for loop. My answer is not sorted. Why? I follow the above algorithm in Python 3.0. My ...
22 views

### Questions on a Python Creational Design Pattern

I came across a potential creational design pattern when programming in Python that I haven't seen before and I wanted to get some opinions on whether it is advisable to use this approach. Problem: ...
146 views

### Algorithm to return all possible ways to divide n unique elements into groups of size k

If I have as set N of n unique elements, is there a known algorithm that can return every possible way in which they can form groups of size k? Eg: If N = { A, B, C, D} and k = 2, then the algorithm ...
73 views

### speed up straightforward solution using dynamic programming

i recently got onto the following problem: we consider the following array: A = [2, 3, 6, 1, 6, 4, 12, 24] we need to count the number of times these two ...
63 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 ...
32 views

### Merge N number of euclidean distance matrices to get an overall single euclidean distance matrix

I want to find out the aggregated euclidean distance of a big dataset D comprising of x and y cordinates where the data set is divided into N sub dataset where 1st sub dataset contains 1 to kth ...
14 views

### Ratio of intra-class scatter by inter-class scatter is getting minimised by linear discrimination process

I am optimising projection matrix P using Fisher linear discrimination formula maximise following with P J=N*tr(trnspse(P).SB.trnspse(SB).P) / c * tr(trnspose(P).SW.transpose(SW).P) As per theory, P ...
55 views

### I am working on project euler 52 to practice my Python but I think I have misunderstood what the problem is

It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order. Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, ...
192 views

### “Converting” networkx / osmnx graph to a planar graph

I am currently working on some analyses of the Berlin road network, and I am using OSMNX to get a relevant graph representation. I noticed that - if with drawbacks - many authors use planar ...