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

Why do online compilers/interpreters use different limits for the maximum recursion depth error?

When using two different online Python compilers/interpreters for executing a program (this one, and this one), I found that both sites showed the maximum recursion depth error at $n = 998$, whereas ...
0
votes
2answers
11 views

Longest common subsequence solution reconstruction during DP is wrong

I've implemented longest common substring in python. I know the usual way to reconstruct the path. But, I am reading my algorithm many times, I don't understand why ...
0
votes
0answers
17 views

How do I create a orthagonal projection of Canada from a shapefile in Python? [closed]

I am currently trying to make a orthagonal projection of Canada in order to produce a heat map. I need the projection to be as if Canada was placed on a 3D globe.
1
vote
1answer
34 views

Loop invariance insertion sort algorithm

I have the following pseudo code for a insertion sort algorithm ...
0
votes
0answers
18 views

I need good book about algorithms, which explains recursion, backtracking and depth first recursion for beginners [duplicate]

I'm learning programming, Python 3 in particular, and I have a good book "Beginning Python - From Novice to Professional" by Magnus Lie Hetland, but the book doesn't explain algorithms at ...
1
vote
0answers
68 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 ...
-1
votes
1answer
112 views

Time and space complexity

...
-2
votes
1answer
22 views

How to multiply all odd numbers between 50 and 100 in python [closed]

I'm new to to python and tried a lot to solve this but can't get this right. I need help on this Thank you The code I wrote is - ...
1
vote
1answer
22 views

Notations for dealing with generators in algorithms

This question is about generators, which are functions that return an item from a (usually very large or infinite) set on demand, an example from Python is: ...
0
votes
1answer
24 views

Reassigning BT root and its children

Given the root of a binary tree, for instance below, I am running the following tests in Python: 1 / \ 2 5 / \ 3 4 Test 1: ...
0
votes
1answer
18 views

How to position images within a canvas while avoiding overlapping

I have a canvas. On this canvas, I want to position 1, 2 or 3 images. The images can be positioned anywhere on the canvas just as long as they're within the canvas. The images move by their top-left ...
1
vote
1answer
41 views

How to create a subset with a given length and mean?

I have a set of numbers $P=\{p_1,\dotsc,p_{|P|}\}$, where $|P|$ is the length of the set. I want to select a subset, $S$, from $P$ such that its mean is approximately equal to a predefined value $\...
0
votes
0answers
13 views

How do I choose the right model for production?

I am trying to build a classification algorithm having 28 classes. These classes consists of Logo of companies like adidas , Nike etc. I have very low dataset below than 100 images and greater than 70 ...
1
vote
1answer
29 views

Which pretrained model will be best for my dataset?

I am trying to build a classification algorithm having 28 classes. These classes consists of Logo of companies like adidas , Nike etc. I have very low dataset below than 100 images and greater than 70 ...
0
votes
1answer
64 views

If i use other peoples code for my final year project does that come under Plagiarism?

I want to make a facial recognition project but my coding ability is very limited so I am going to be relying on other peoples code but if i use their code even if i change the variables and make ...
0
votes
0answers
31 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 ...
1
vote
1answer
24 views

Finding optimal separating value

Problem description We are given two sorted arrays of even numbers: A and B. Values of A are generally supposed to be smaller than values of B. So we are asked to find a value X where X is an odd ...
0
votes
2answers
68 views

How to make a directed graph in python?

I am working on my own personal project. I took an intro to coding class last semester so I have been exposed to coding but I am still lost with it. Basically, for my project, I want to build a web ...
0
votes
1answer
40 views

Recursive array

The following is a function to write a recursive function that accepts an array and a callback. Function returns true if a single value in array returns true when passed to the callback otherwise it ...
0
votes
0answers
23 views

Python 3 multiprocessing stacktrace CUDA failure?

I am working on a data processing script and trying to use multiprocessing so that it runs faster. Whenever I run the python script, I get the following error: 2020-12-24 18:30:22.679414457 [E:...
0
votes
0answers
7 views

How to set parameters in Librosa's CQT function for an 88-key piano?

I am doing an automatic music recognition project with a deep learning model. For my data preprocessing, I am trying to calculate the Constant Q Transform for Polyphonic 88-key piano audio using ...
0
votes
0answers
7 views

Prophet Model in Batch Implementation

I am newby at Prophet model. I was wondering Prophet uses stochastic or batch approach while in training. If it uses stochastic that means there is nothing to do convert and compute mini batch ...
0
votes
0answers
20 views

Why is KMP preprocessing O(N)?

My intuition tells me that there is <=1 increase in lps for each increase in the index. Can someone make a better argument why this is O(N)? My confusion arises from ...
0
votes
0answers
20 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 ...
0
votes
0answers
9 views

building a unsupervised learning model to detect suspicious transactions using DBSCAN

I am working for the first time on building a unsupervised learning model to detect suspicious transactions using DBSCAN, Do I train the model on all data columns(Columns like account number, ...
0
votes
0answers
40 views

Big O of my backtracking solution

I have a problem and I've been struggling with my solution time and space complexity: Given an array of integers (possible duplicates) A and ...
0
votes
0answers
37 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 ...
1
vote
1answer
42 views

Finding the area of a rectangle in python [closed]

Q: Standard input consists of exactly four integers, first x1 and y1, the coordinates of the bottom-left corner of a rectangle, then x2 and y2, the coordinates of the top-right corner. Write a Python ...
1
vote
0answers
47 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 ...
1
vote
2answers
45 views

Closed form of recurrence with two inputs

This question comes from a relatively simple coding challenge at Codesignal, but represents an interesting CS/math puzzle. The question states: "When a candle finishes burning it leaves a ...
2
votes
0answers
30 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 ...
1
vote
2answers
86 views

Lambda Calculus Conversion

How can I take a Haskell data type or function (eg fold, list, String, zip) and convert or translate it to a lambda calculus abstraction? Example: If sum computes a sum of all elements in a list, and :...
1
vote
0answers
51 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 ...
0
votes
1answer
53 views

Combinations of set unions

I have a set $S = \{0,1,2,3,4,5,6,7,8,9\}$. $S_i \subset S$ for $i = {1,2,3,4,5}$. Any three $S_i$ has the same union, that is $S_1 \cup S_2\cup S_3 = S_1\cup S_2\cup S_4 = ...=S_3\cup S_4\cup S_5 = A$...
0
votes
0answers
21 views

Sorting idea - using little buckets (Not BucketSort)

I am recently been doodling with sorting, thought about writing my own ideas, and what I am about to write here came to my mind, and I am writing it here because I do not know if such sorting idea ...
1
vote
2answers
46 views

What programming language should I use to run physics simulations of CO2 being absorbed by different materials?

I want to model the absorption of CO2 with multiple different materials such as cement, limestone, wood, etc? I know Matlab is capable of these types of physics simulation according to this research ...
0
votes
1answer
234 views

What is the difference between python list and c++ vector?

I read about the similarities between the python list and c++ vector and it looks as if the only difference is python list is heterogeneous. Are there any other differences? How are they both ...
8
votes
7answers
4k views

Checking equality of integers: O(1) in C but O(log n) in Python 3?

Consider these equivalent functions in C and Python 3. Most devs would immediately claim both are $O(1)$. def is_equal(a: int, b: int) -> bool: return a == b <...
4
votes
3answers
1k views

What is the expected time complexity of checking equality of two arbitrary strings?

The simple (naive?) answer would be O(n) where n is the length of the shorter string. Because in the worst case you must compare every pair of characters. So far so good. I think we can all agree that ...
0
votes
0answers
14 views

Do Predecessors Ever Get Updated in Depth-First Search?

Is it true to say that in a Depth-First Search that uses a dictionary of predecessors to find the path to its destination, once a node has been pushed onto the stack and been added to the predecessors ...
1
vote
1answer
44 views

A pretrained model for mathematical equations characters detection

I am working on a project to convert equations to LaTeX code. After segmenting out the characters, I got stuck on the detection part and was looking for some pre-trained model that could detect ...
0
votes
3answers
118 views

Can a 600 MB text file with digits of the square root of 2 be compressed to 600 KB?

I have a simple script to calculate gaps in a sequence of digits of the square root of 2 (or any other multi-precision constant). As input, I generated files with the bigfloat module in Python: ...
0
votes
0answers
6 views

modeling DNS server CPU utilization on simulator framework

I'm creating my simulation framework, the DNS system. I have two related questions about the name server. I would like to know how much time the Authoritative Name server spends time to resolve one ...
0
votes
0answers
16 views

How to pick a random index in an array based on the index's value?

While solving a problem on leetcode, I used a heap to give the largest probable value. The problem statement is as follows: Given an array w of positive integers, where w[i] describes the weight of ...
0
votes
0answers
8 views

Is there any pseudocode of generating special orthogonal group which I can used for reference?

So, I want to include pseudocode of generating special orthogonal group for my thesis and I need something like a paper which I can refer to. I use this Scipy function to generate SO(n) and there is a ...
1
vote
1answer
40 views

Meaning of this python modulo operator exercise?

I just got started with Python PCEP course material on netacad.com. I've come across the following exercises: 2 % -4 = -2 2 % 4 = 2 As I understand it, ...
0
votes
0answers
16 views

3D reconstruction from multiple images

Sorry if it's a trivial question but I'am a beginner. I am working on 3D reconstruction from multi-images project. I am working with these datasets. There is a par.txt file including the camera ...
1
vote
0answers
31 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 ...
1
vote
1answer
130 views

How to wiggle sort an array in linear time complexity?

The wiggle sort is nums[0] < nums[1] > nums[2] < nums[3] > nums[4] ... For an input: nums = [1, 5, 1, 1, 6, 4], the expected output is ...
-2
votes
1answer
124 views