All Questions
203 questions
2
votes
2
answers
410
views
Median of two sorted arrays in Python
Problem Statement
(Source: Leetcode Problem 4: Median of Two Sorted Arrays [Hard])(Topics: [Array] [Binary Search] [Divide and Conquer])
Given two sorted arrays ...
4
votes
1
answer
81
views
Array Math to Calculate Ice Thickness -- Need Help Simplifying
I posted this on Stack but since it's working code, it was suggested I post it here. I wrote this code to calculate ice thickness using the following equation from Stephenson, 2011.
It's a daily ...
2
votes
1
answer
217
views
Hackerrank "New Year chaos" solution - permute sequence by swapping adjacent terms
I was doing the Hackerrank "New Year chaos" problem. Here is the description:
It is New Year's Day and people are in line for the Wonderland
rollercoaster ride. Each person wears a sticker ...
4
votes
1
answer
131
views
Finding the earliest time we can schedule
We have a list of \$j \in \{1,\ldots,N\}\$ jobs with a processing time \$p_j\$ and a demand \$d_j\$ between 0 and 1. These are real numbers. Jobs require the fixed demand over the entirety of their ...
4
votes
4
answers
1k
views
Merging sorted integer arrays (without duplicates)
I have written a Python function called merge_arrays which takes two lists and returns the new list merge without duplicate.
The function works as expected, but my ...
5
votes
4
answers
2k
views
Automate the boring stuff with python - Character picture grid
Character Picture Grid
Say you have a list of lists where each value in the inner lists is a one-character string, like this:
...
4
votes
3
answers
766
views
Determine whether two arrays have the same elements with the same multiplicities
I have written a Python function called comp that checks whether two given arrays have the same elements, with the same multiplicities. The multiplicity of a member ...
1
vote
1
answer
62
views
Optimizing the Dig Pow function
I have written a Python function to solve the Dig Pow problem, where the goal is to find a number k such that the sum of each digit of n raised to a specific and ...
2
votes
1
answer
394
views
Generating random number of randomly sized Squares/Rectangles using numpy arrays
I made classes to use in generating square/rectangular shapes on a texture.
...
1
vote
0
answers
163
views
Smallest interval whose sum exceeds a threshold
In a non-negative 1D array x, we wish to find the shortest slice such that x[start:end] > threshold, with constraint that <...
2
votes
1
answer
139
views
Returning all divisors of a number as a matrix with N X 2 dimensions
I have developed a class structure with methods to return a matrix from a single input array. The objective is to insert the middle value of the array so 2n remains ...
5
votes
2
answers
329
views
Porting PHP's array_push to Python
I am new to Python but not new to PHP. I've started porting PHP APIs to Python hoping to learn the Python language along the way, currently trying to grasp List, Dict, Set, Tuple. I tried writing PHP'...
5
votes
1
answer
232
views
Why is this tensor contraction so slow and how can I make it faster?
I am trying to calculate a specific complicated tensor contraction (of complex valued tensors) which appears as part of some other calculation and is called multiple times in a row, about 100 times or ...
2
votes
1
answer
266
views
Replace nested for loops when assigning intial conditions in a 4-dimensional array
I create a 4-dimensional (x, y, z, t) array of zero values. I then set the initial values at t = Tmax. To do this, I use a nested for loop. I attempted to improve ...
4
votes
2
answers
1k
views
Find all indices where value of array changes
I try to solve the following problem using Python:
Given a 1-dimensional numeric array arr, find all indices where the value of ...