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

need help with a project python

Description: In this work you will have to design the logic and implement the code in python language in order to display (real time) information about the weather in five areas of Greece: Athens, ...
-4
votes
0answers
17 views

Loops converting into a for loop [closed]

Convert the following while loop into a for loop. Your code should be written so that the return statement does not need to be altered. You are allowed to change the code before the while loop proper. ...
1
vote
1answer
46 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 ...
0
votes
0answers
7 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 ...
-1
votes
0answers
9 views

FailedRequest server error 520 when sending message using PyTextNow

Over the summer, I was successfully using the PyTextNow python library to send text messages from my raspberry pi to my phone with python. I stopped using it for a while, around a month. When I tried ...
0
votes
0answers
13 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 ...
0
votes
0answers
16 views

How can I write a python code to display the geometric progression showing the number of coin tosses required to obtain a heads [closed]

I am trying to create data for an assignment. I need data to show the probability of getting a heads in 1 toss, two tosses, three tosses and so on. Ideally, the probablity is the sequence p, (1-p)p, (...
-2
votes
0answers
17 views

Time analysis of merge sort and insertion sort

I want to write a program that analyses the time taken for merge sort and insertion sort. I want to plot the time taken for the algorithms to sort a list and vary the size of the input list to see how ...
1
vote
1answer
31 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 ...
0
votes
1answer
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 ...
0
votes
0answers
18 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: ...
0
votes
1answer
76 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 ...
0
votes
1answer
56 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 ...
0
votes
0answers
39 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 ...
0
votes
0answers
19 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 ...
0
votes
0answers
12 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 ...
-1
votes
1answer
37 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, ...
2
votes
1answer
88 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 ...
0
votes
0answers
15 views

What is the point of Transforms in Pytorch when loading Dataset?

I am not sure what the point of the data augmentations in PyTorch when loading images. Specifically, I am talking about this: ...
0
votes
0answers
28 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: ...
3
votes
0answers
19 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 ...
-1
votes
1answer
38 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
42 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
68 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
20 views

Difference between specifying argument and not in NumPy [closed]

Running these lines in Colab: ...
0
votes
1answer
29 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
19 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
31 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
21 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
35 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
90 views

Python versus Matlab on the quantity 1/0

Python and Matlab seem to disagree on the division by 0. Python: ...
0
votes
1answer
27 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
138 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
36 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
30 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
23 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
7 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
32 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
41 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
9k 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
370 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
31 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
30 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
59 views

Loop invariance insertion sort algorithm

I have the following pseudo code for a insertion sort algorithm ...
0
votes
0answers
21 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
71 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
2k views

Time and space complexity

...
-2
votes
1answer
72 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: ...