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
0answers
11 views

Connected component- feature regions extraction

I'm trying to extract the connected component from a graph, in the following way: ...
0
votes
0answers
23 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: ...
1
vote
0answers
11 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 ...
0
votes
0answers
13 views

I have to check the answer to this question that I developed, in order to verify if the code and question are correct, can you answer to this [closed]

2k precedes 2k−1 in a if k precedes 2k then 2k+1 precedes k in a k precedes 2k in a
-4
votes
0answers
19 views

Question is in picture [closed]

!find answer of question in image]1
-1
votes
1answer
36 views

Generate 3D “matrix” with Pandas, based on comparing two dataframes [Python] [closed]

Good morning everyone. I am working with Python and Pandas. I have two DataFrames, of the following type: ...
3
votes
1answer
36 views

What's the runtime complexity of this algorithm for breaking up string into words?

I am given a input string $s$ ("bedbathandbeyond") and a set of words {"bed", "bath", "beyond", "bat", "hand", "and"}. I need to ...
1
vote
2answers
64 views

Why does Python allow stand-alone expressions?

In Python, this is a valid program def PrintWorld(): print('World') print('Hello') 0 'beautiful' True None 0 < 0 3, 3 lambda c:3 PrintWorld() All it does ...
0
votes
1answer
19 views

Difference between specifying argument and not in NumPy [closed]

Running these lines in Colab: ...
0
votes
1answer
28 views

Insertion sort Pseudo code vs implementation?

So I'm trying to implement an insertion sort algorithms based on page 18 Cormen psuedocode but I'm confused by ...
2
votes
0answers
18 views

What is an algorithm to do this binary image segmantation task?

What I need to do is go from a binary image like this: to a segmented structure like this: because I have a program that operates on those separated line contours after. As you see, those contours ...
0
votes
0answers
30 views

Simulating a multi-network environment in one device using Python

I am deploying a blockchain on a localhost where all nodes can communicate with each other using ports and APIs; however, a node/group of nodes can leave the main blockchain group. Some questions came ...
0
votes
0answers
20 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 ...
1
vote
0answers
14 views

Conversion of a YAML file to XLSX using Python [closed]

I want to convert a set of yaml files in a folder into an xlsx file. I thought I'd start with trying to convert one yaml file into an xlsx file. The yaml files in the folder are all in the format ...
3
votes
2answers
87 views

Python versus Matlab on the quantity 1/0

Python and Matlab seem to disagree on the division by 0. Python: ...
0
votes
1answer
24 views

K Nearest Neighbor using K-D Tree (What ratio makes K-D beneficial)?

I'm trying to implement a KNearestNeighbor model and came across the fact that many professional models use a K-D tree to index the K Nearest Neigbors. I also read that high-dimensional data makes a K-...
-1
votes
1answer
105 views

Is radix sort in-place or out-place?

Generally, we can implement algorithms in-place and out-of-place. However, I can't say for certain that radix sort can be implemented in both ways.
0
votes
0answers
29 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 ...
0
votes
1answer
29 views

Removing a character from a string

I am asked the following: def myRemove( str, ch ): # Return a new string with the first occurrence of ch removed. If there is none, return str. Sample run ...
0
votes
0answers
22 views

Parsing HTML from HTTP vs HTTPS websites

Are there any alternative steps to receiving and then parsing the HTML of an unsecured site (HTTP) vs a secured site (HTTPS)? I am asking as I learnt that there is encryption involved in the HTTPS ...
1
vote
0answers
6 views

Calculate coherence for non-gensim topic model [closed]

I've built a topic model, with: Input: list of tokenized lists Output: a m x t matrix (with each cell indicating the probability of word i appearing in topic k). Output: a k x n matrix (with each ...
0
votes
1answer
25 views

Travelling Salesman Problem with Memoization

I coded a solution for the famous Travelling Salesman Problem but my code does not work properly, although it seems okay. In a grid of size m x n, you are allowed to move only down/right, and you ...
1
vote
2answers
38 views

parse datetime number in html field

This is a sample of datetime field: 1615717137369 It means 2 days ago (from 16 march, 13:24) How can I parse the number? P.S: These are some examples: ...
7
votes
12answers
5k views

Time complexity of min() and max() on a list of constant size?

If you use min() or max() on a constant sized list, even in a loop, is the time complexity O(1)?
-1
votes
1answer
17 views

largest gcd of an array after a few operations

consider we have n bags of random amounts of coins. given k extra coins, the question is to find the largest gcd that can be ...
1
vote
1answer
113 views

Can someone help me understand the time and space complexity?

Can anyone help me understand the time and space complexity here? I know zip() is O(1) and sorted() is O(n). The loop has the ...
0
votes
0answers
29 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
19 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 ...
1
vote
1answer
46 views

Loop invariance insertion sort algorithm

I have the following pseudo code for a insertion sort algorithm ...
0
votes
0answers
20 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
70 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
158 views

Time and space complexity

...
-2
votes
1answer
27 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
24 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
25 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
23 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
44 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
14 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
36 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
98 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
40 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
134 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
65 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
68 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
12 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 ...
2
votes
1answer
57 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
25 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
11 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, ...