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.

Filter by
Sorted by
Tagged with
-3 votes
0 answers
13 views

python django- adding a like function button [closed]

I am trying to add a like function to my blog, but I keep getting this error.
african_geek's user avatar
0 votes
1 answer
29 views

What is the practical use of list.clear() method in Python?

I was wondering if there is a reason behind clearing all the values in a list and reusing it, as opposed to deleting the list and creating a new one. Are there any practical advantages of using ...
Akshay Katiha's user avatar
-4 votes
0 answers
36 views

Maximum possible coincidences? Python code please [closed]

Given $M = [0,4,8,15]$ as points on a real line place 2 points $C_1$, $C_2$ on the line according to the following conditions Both $C_1$ and $C_2$ cannot be placed at 0 or 15. Distance between $C_1$ ...
Vamsi Krishna Kunapareddy's user avatar
0 votes
0 answers
32 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
1 vote
0 answers
12 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
0 votes
0 answers
37 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
1 answer
34 views

Should I concatenate three lists together or use two separate while loops in Python? Which option offers a better runtime complexity?

In the context of adding sparse polynomials, you have two alternative approaches to combine the terms from two separate polynomials. One option is to use the line of code ...
alefvanoon's user avatar
0 votes
1 answer
85 views

Why boolean value in Python is 24/28 bytes?

What is the reason for this behavior? Usually, in other programming languages, it is either 4/8 bytes, if I am correct.
kjkjkjkjkj's user avatar
0 votes
1 answer
29 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
1 vote
0 answers
51 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
0 votes
1 answer
23 views

Combining chunks on an infinite grid into regions

I am working on an floorplan application where I save elements on an infinite grid in a sparse manner. Specifically, I have the following Python class representing a sparse grid (basically a ...
Mate de Vita's user avatar
0 votes
0 answers
21 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
53 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
-2 votes
4 answers
109 views

Can halting problem solved by soft computation?

As far as I know, the halting problem means we can't create a program that checks whether another program is stuck or halt based on given input. This means, the program expects two inputs and one ...
Muhammad Ikhwan Perwira's user avatar
-1 votes
1 answer
114 views

Design an algorithm to predict words based on a skeleton from a given dictionary

I'm working on an algorithm which is permitted to use a training set of approximately 250,000 dictionary words. I have built and providing here with a basic, working algorithm. This algorithm will ...
driver's user avatar
  • 99
1 vote
1 answer
81 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 votes
1 answer
52 views

Detecting if an object reached target points

I have an object that is moving towards target points and I want to determine when it will reach or pass through them. I receive points in real time, which represent the current position of the object....
theateist's user avatar
0 votes
0 answers
66 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
89 views

Why does Python behave so absurdly when dealing with numbers with decimal points?

r1 and r2 both are assigned 0.05 initially. If r1 is incremented by 0.01 in this way "r1 = r1 +0.01" we have 0.060000000000000005 as answer not 0.06.
Pulakesh Bag's user avatar
0 votes
0 answers
5 views

Reproducible research (published papers) about e-commerce or fashion

I am looking for reproducible research (published papers) about e-commerce and/or fashion which deals with exploratory data analysis, hypothesis testing and regression or ANOVA. This reproducible ...
Yumunus's user avatar
0 votes
3 answers
72 views

Number of islands

In the counting number of islands problem, I noticed that one of the solution from internet is as follows ...
SKPS's user avatar
  • 103
0 votes
0 answers
14 views

Python | Normalized Vector Based Player Controller

I recently started writing a 3D Engine using the Math Library, and PyGame for Graphics. I've made a simple demo scene, but I would like to make a "First-Person" like Camera Controller. I've ...
Landen Barker's user avatar
0 votes
2 answers
35 views

Discarding lists of same elements

Suppose, I have a list of lists where multiple lists can have same elements. In my final output, I just want one list with the same element. An example is the following: Input: A=[[1,2,0], [0,1,2], [2,...
Becker Mammat's user avatar
0 votes
2 answers
75 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
1 answer
97 views

Can somebody explain to me the concept of mutability with respect to a NumPy array?

From the NumPy documentation: "NumPy arrays have a fixed size at creation, unlike Python lists (which can grow dynamically). Changing the size of an ndarray will create a new array and delete ...
NaiveBae's user avatar
  • 101
11 votes
5 answers
3k views

Does an algorithm's space complexity include input?

Consider the Kadane's algorithm for finding maximum subarray within an array: ...
Eugene Yarmash's user avatar
0 votes
1 answer
42 views

How sparsity term in loss function for sparse autoencoder is making hidden units inactive?

I am working on a Sparse Autoencoder but Andrew NG's notes are hard to understand. My question is about the following equation: Loss Function. In sparse autoencoder, the goal is to inactive some ...
p200401Samuel's user avatar
1 vote
1 answer
35 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
1 answer
54 views

Having a 2D matrix with three typed elements, how to efficiently cover one of the types and NOT cover the other one?

I have a matrix with three possible elements: A, B and C. The size of the matrix could be a maximum of 15x16. $$ \begin{bmatrix} A & A & C & A\\ A & C & B & C\\ A & C & ...
Superluminal's user avatar
1 vote
1 answer
115 views

How can I convert the pseudo-code that solves maximum subarray problem to Python code?

I'm reading Algorithm Design and Application, by Michael T. Goodrich and Robert Tamassia, and sometimes the pseudo-code in this book doesn't make sense at all. At chapter one they show us 3 solutions ...
André Carvalho's user avatar
0 votes
1 answer
101 views

Finding whether a point lies on the boundary of an geometrical object or not?

Suppose I have the mesh of an geometrical object (Interval in 1d, Region in 2d, Volume in 3d). How can I find out whether a point lies on its boundary or not? I am looking for algorithms with ...
FreeMind's user avatar
  • 111
0 votes
1 answer
80 views

Design an algorithm to calculate stock prices on a given day

Given a list of lists containing tuples in sorted(by day) order find and print the total number of stock units owned for every day that occurs at least once. ...
Remixt's user avatar
  • 99
2 votes
4 answers
114 views

Algorithm that finds 4 "O"s or 4 "X"s on a diagonal, horizontal, or vertical

My algorithm homework revolves around matching 4 "O"'s or 4 "X"'s on a diagonal, horizontal, or vertical. ...
bbartling's user avatar
  • 123
1 vote
2 answers
388 views

Is the complexity of this two-sum binary search algorithm $O(\lg n)$ or $O((\lg n)^2)$?

This algorithm solves the Two-Sum problem$^1$ assuming that the input array/list is sorted. ...
joseville's user avatar
  • 115
1 vote
0 answers
35 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
0 votes
1 answer
239 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 ...
PK96's user avatar
  • 71
3 votes
2 answers
685 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 ...
Kelly Bundy's user avatar
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
-5 votes
1 answer
511 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 ...
Hill Paul's user avatar
0 votes
1 answer
200 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 ...
Daniel's user avatar
  • 1
0 votes
0 answers
192 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
3 votes
1 answer
142 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 ...
Rodrigo's user avatar
  • 189
2 votes
2 answers
648 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 ...
Rodrigo's user avatar
  • 189
2 votes
1 answer
63 views

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

Say we have this algorithm in Python. ...
CSch of x's user avatar
1 vote
1 answer
147 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 ...
sfhdfh23's user avatar
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
2 answers
261 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 : ...
charon25's user avatar
  • 121
1 vote
0 answers
27 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
0 votes
0 answers
57 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
1 vote
1 answer
188 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. ...
PK96's user avatar
  • 71

1
2 3 4 5