All Questions
45 questions
1
vote
1
answer
74
views
Vectorized code to find the position and length of runs of 1s in a bit matrix
I'm trying to write something like an adjusted run-length encoding for row-wise bit matrices. Specifically I want to "collapse" runs of 1s into the number of 1s in that run while maintaining ...
2
votes
2
answers
790
views
Finding distance between vectors of matrices
So here is the problem:
Given 2D numpy arrays 'a' and 'b' of sizes n×m and k×m
respectively and one natural number 'p'. You need to find the
distance(Euclidean) of the rows of the matrices 'a' and ...
2
votes
1
answer
820
views
Finding the Euclidean distance between the vectors of matrix a, and vector b
Here is the problem,
Given a 2D numpy array 'a' of sizes n×m and a 1D numpy array 'b' of
size m. You need to find the distance(Euclidean) of the 'b' vector
from the rows of the 'a' matrix. Fill the ...
4
votes
1
answer
291
views
Generating unique 2D numpy arrays with 2 adjacent row elements swapped while using BFS in Python
So I have a 12 x 6 2D numpy array for input which consists of 7 possible board objects (characters from 'abcdefg'). From a 2D numpy array I wish to generate all the possible unique 2D arrays, in whose ...
3
votes
1
answer
50
views
How to optimize code to take advantage of NumPy broadcasting when calculating pairwise correlation?
I'm trying to take advantage of NumPy broadcasting and backend array computations to significantly speed up this function. Unfortunately, it doesn't scale so well so I'm hoping to greatly improve the ...
7
votes
4
answers
3k
views
Pad a ragged multidimensional array to rectangular shape
For some machine learning purpose, I need to work with sequences with different lengths. To be able to process efficiently those sequences, I need to process them in batches of size ...
2
votes
1
answer
51
views
Calculating the potential of a matrix of size (424600, 55)
I have the following working code to calculate the potential of a matrix after normalizing the matrix. But it is too much time consuming. Is there a way to make this code run faster?
...
2
votes
1
answer
5k
views
Inverse mapping with bilinear interpolation on an image
The following is my solution for an inverse mapping with bilinear interpolation on an image. The original image is img and ...
3
votes
1
answer
86
views
MinMax product for large matrices
I created this program which runs with no error, but I'd like to have some comments if it is possible to optimize it, since I need to run the program with N = 3200. ...
12
votes
1
answer
1k
views
Looking for a way to create a particular matrix in python in a less amount of time
I want to create a matrix like this in Python:
$$
\begin{pmatrix}
0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 2 & 2 & 2 & 2 & 3 & 3 & 3 & 3\\
0 & 1 &...
2
votes
2
answers
83
views
Eigenvector calculation involving three matrices
Code performs well for small matrices, but gives memory error for large matrices of size 63000x93000, even when I am using server with memory of 64GB, space 100GB, swap 40GB.
...
1
vote
1
answer
65
views
Extended matrix generation
I am extending a matrix with some calculated values. This code runs very slowly.
Is there a way to vectorize this with slice and ...
5
votes
1
answer
9k
views
Gaussian Elimination with Pivots
I'm pretty new to python, and coding in general. For practice, I've written the following code, which uses Gaussian reduction to solve a system of linear equations.
...
1
vote
1
answer
5k
views
Generating a word bigram co-occurrence matrix
I have written a method which is designed to calculate the word co-occurrence matrix in a corpus, such that element(i,j) is the number of times that word i follows word j in the corpus.
Here is my ...
3
votes
0
answers
50
views
Deriving incremental feature representations for bit flips
Given a boolean 3D matrix and a set of actions specifying bit flips at certain positions, a set of resulting matrices can be obtained, one matrix for each action, as if executing each bit flip ...