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
-1 votes
0 answers
8 views

Need help while writing a code about how to acess value of a label which was executed by while loop in tkinter [closed]

[![the picture here shows the code and run through [I was completing my school project using tkinter GUI .. the problem here is while working on the railway management system I wanted to input the ...
Chiku's user avatar
  • 1
0 votes
0 answers
23 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
70 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
84 views

Mutation using scrambling, in genetic algorithm, which fails to converge

I have a piece of Python code I would appreciate help with. As the title says, the code will not converge. I reaches 90-95% accuracy after a few generations, but afterwards it becomes stagnant. Here &...
NumberMan'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
51 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
12 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
1 answer
27 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
65 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
39 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
9 votes
4 answers
2k 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
20 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
33 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
49 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
91 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
67 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
70 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
0 votes
0 answers
19 views

Intensity dependent erosion

Let’s say you have an image in the form of an 2D numpy array in python as the one below. Now you want to eroded the image. HOWEVER, you don’t want to erode it equally. It should be eroeded only if the ...
jhvn's user avatar
  • 1
0 votes
0 answers
17 views

Determine if a tree is connected from top to bottom

Consider the following scenario: you have a "tree", and it got many levels, each fill with nodes. nodes could only connect to other nodes that is one level above or below it. the connection ...
CodingNoomb's user avatar
2 votes
4 answers
104 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
0 votes
0 answers
15 views

Is there a python library for generating a mass-spring model?

Given a 3D representation like mesh or point cloud, I want to generate a mass-spring model of it. By mass-spring model I mean this. Is there a python library for doing this?
user709512's user avatar
1 vote
2 answers
265 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
24 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
169 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
468 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
891 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
421 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
147 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
176 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
125 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
642 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
62 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
126 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
28 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
187 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
23 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
36 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
174 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
-4 votes
1 answer
171 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 ...
Omoba P.'s user avatar
0 votes
0 answers
22 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
1 vote
1 answer
70 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 ...
graphicart86's user avatar
1 vote
1 answer
24 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 ...
graphicart86's user avatar
1 vote
1 answer
40 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 ...
graphicart86's user avatar
0 votes
2 answers
185 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 ...
Brett Cooper's user avatar
0 votes
1 answer
26 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. ...
Azuur's user avatar
  • 3
4 votes
1 answer
656 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 ...
Steven Zeng's user avatar
0 votes
0 answers
245 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
4 votes
1 answer
158 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 ...
Tortar's user avatar
  • 167
0 votes
1 answer
45 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 ...
nave's user avatar
  • 3
1 vote
2 answers
241 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 ...
OneRaynyDay's user avatar