In mathematics, a matrix (plural matrices) is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. The individual items in a matrix are called its elements or entries.
2
votes
0answers
31 views
Parallelize (or otherwise speed up) a double loop over a symmetric matrix [duplicate]
I wrote a non-vectorized, non-parallel wrapper function for computing the pairwise distance covariances (Wikipedia) (original paper) in a data frame:
...
4
votes
0answers
33 views
Translating array pointer access from C++ to Delphi
I'd like to know if I translated a piece of code correctly from C++ to Delphi. It looks like it is working, but I have a feeling that I'm reading and writing into memory that I'm not supposed to using ...
3
votes
1answer
42 views
Square spiral matrix
I've written a Python script to generate the closest square spiral matrix to a given number.
I'm new to code reviews as a practice, and I'm interested in ways to improve. Please suggest improvements ...
3
votes
2answers
313 views
Rotating an NxN matrix
I came up with the following solution for rotating an NxN matrix 90 degrees clockwise, to solve this CodeEval challenge:
Input
The first argument is a file that contains 2D N×N matrices ...
1
vote
1answer
32 views
Optimize matlab triple for loop
I have a large matrix samples, I want to make another matrix sampleProb which is the same size, but modified as below:
...
1
vote
0answers
10 views
Functions for outputting the rows and columns of a matrix
I often want to iterate either row-wise or column-wise though a matrix in Julia, so I've created a pair of functions to help:
...
6
votes
2answers
86 views
Find element in sorted matrix
Find an element in a MxN matrix where each row and column is sorted in ascending order.
Any comments on my code?
(I added some test cases on non square matrices which I did not copy here)
...
5
votes
4answers
158 views
Mathematical matrices implementation
As a Java programmer who's trying his hand at C++, I thought I'd start building a library for working with matrices as my first C++ project. I've got very little C++ experience and it's been a long ...
3
votes
1answer
74 views
Divide all elements in the column of a sparse matrix
Using Python Scipy, I am trying to divide all numbers in all columns of a sparse matrix (400K × 500K, density 0.0005), by the sum of the squares of all numbers in a column.
If a column is ...
1
vote
1answer
63 views
Performing Gauss-Jordan elimination on a matrix in Java
I have this small "framework" for representing matrices with entries of primitive type double, and performing Gauss-Jordan elimination (for solving systems of ...
8
votes
2answers
173 views
Symmetric Square
I was given an assignment to ensure that a list was symmetric.
I built it in a way that worked and it passed the tests. But I wanted to see if it could've been written more efficiently and still ...
5
votes
2answers
72 views
Opening and writing multiple files using minimum script
Can it possible to make this script short, so that multiple data and multiple output file can be managed efficiently?
...
6
votes
2answers
85 views
Gauss elimination
The gauss function takes 3 parameters:
a pointer to the matrix of coefficients
the number of variables
a pointer to matrix of solution
...
14
votes
1answer
141 views
Remapping and interpolating 255x1024 array
I have a function that accepts a \$255\times1024\$ array and remaps it to another array in order to account for some hardware related distortion (lines that should be straight are curved by the lens). ...
2
votes
1answer
62 views
Determinant of a matrix
I'm visiting some code that I wrote for one of my finals projects and wanted to know whether there were a more optimal, more elegant way to do this so it does not look so "hard-coded".
The problem ...
4
votes
2answers
73 views
Hardcoding matrix multiplication
I was doing a problem, SPOJ: FLIB. My code was running slow (getting Time Limit Exceeded error) when I was using Code1.
However, my code accepted within the required time limit when I hardcoded the ...
16
votes
2answers
1k views
The grid looked at the menu and said “Something with class, please”
This is a follow up on my previous question:
A grid and a menu walked into a program
I integrated classes into the mix.
The program now asks how big you want the grid to be.
...
2
votes
0answers
86 views
Smoothing matrix for visual representation
I recently started playing around with R and am currently trying to plot GPS data points onto a perspective plot. I have a script that works and I get my desired results out of it and it works ok for ...
1
vote
1answer
42 views
Moving window with complete boundary in Python
I asked this question a few days ago. The question is about producing moving/rolling windows of an array in Python as in the following example:
...
20
votes
2answers
2k views
A grid and a menu walked into a program
A program that creates a grid 10x10 and assigns a random number in each tile. It then asks you if you want to:
create a new grid
view the current one
count how many of each number there are in the ...
3
votes
0answers
53 views
Spiral Scanning for matrix using recursion
I have written code for scanning an N x M matrix in spiral order using a recursive function.
It uses 5 parameters - including 2 extra variables:
call to keep ...
1
vote
1answer
85 views
Faster solution for row-wise matrix subtraction
I have 2 matrices. I have to calculate the euclidean distance between every row of matrix A and every row of matrix B.
In the first solution I loop over the rows of the two matrices and for each row ...
5
votes
1answer
102 views
Optimizing a dynamic programming solution for “Oil Well”
I'm trying to solve the Oil Well problem on Hackerrank using dynamic programming and it works. However, it times out for some of the test cases. I wanted to know how this program can be improved so ...
4
votes
1answer
42 views
Creating a special Toeplitz matrix in R
I'd like to know if there is a standard way of creating a matrix like the one shown below using the R programming language.
$$
\begin{bmatrix}
1 & \rho & \rho^2 & \cdots ...
4
votes
0answers
79 views
Optimization of sparse matrix multiplication for billion by billion matrices
I have to do multiplication of two billion by billion sparse matrices (on a CPU), hence any help or hints in optimizing the below given code would be extremely useful.
Note: I am only showing the ...
6
votes
2answers
96 views
Quaternion rotations and preparing matrices for a shader
I am implementing an OpenGL ES 2.0 renderer in c. I want to use quaternions for rotations. Please take a look at the way I am implementing the rotation math. Everything looks as expected when the ...
2
votes
1answer
66 views
SciPy sparse: optimize computation on non-zero elements of a sparse matrix (for tf-idf)
I have a sparse matrix (term-document) containing integers (word counts/tf) and I am trying to compute the tf-idf, for every non-zero value in the sparse-matrix.
The formula for tf-idf I am using is:
...
5
votes
2answers
57 views
Computing the RPY tensor with C++/Eigen (linear algebra)
I'm mostly used to writing scientific code in MATLAB / Python / Julia and my experience with C++ is very limited. I've implemented a fairly simple computation of the Rotne-Prager-Yamakawa tensor in ...
3
votes
1answer
110 views
Rotate image 90 degree clockwise recursively
Previous question:
Rotate image 90 degree clockwise
In this code I have used tail recursive, which is bad. Time complexity is still \$O(N^2)\$, which is worse-case. The only good part is memory ...
3
votes
1answer
55 views
Simulation of animal skins
This is a simulation of animal skins, like a cellular automat. I'd like it improved.
...
2
votes
1answer
45 views
Memoization for calculating minimal traversal distance within a positive matrix
The code below is for calculating the minimal traversing distance from the top left point of the matrix to the bottom right point of the matrix.
GitHub
Here is the core functionality. Please note ...
10
votes
1answer
108 views
Matrix to Tree Algorithm
The code takes a matrix and turns it into a tree of all the possible combinations. It then "maps" the tree by setting the value of the ending nodes to the total distance of the nodes from beginning ...
2
votes
1answer
51 views
Parsing 2D matrix: “[[1,2][3,4]]”
I feel I am over-complicating things, and that there should be a succinct way to achieve this - perhaps using concepts I have not learnt - or some prelude function I have missed out on.
How can I ...
1
vote
2answers
75 views
2
votes
2answers
71 views
Increase performance of a spate of 2x2 matrix multiplication
I would like to improve the performance of the piece of code below (in Fortran). It gives good results but the profiling tells me that it is where it spends most of its running time.
Basically, it ...
0
votes
1answer
80 views
Matrix: Set a row/col to zero
A practice interview question:
Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.
...
2
votes
5answers
367 views
3
votes
2answers
352 views
4x4 Sudoku solver performance
The code is for a 4x4 Sudoku solver. It works fine when there are a small number of unfilled spaces (0's) but when I give the whole matrix input as 0's or so the solver takes a very long time. I need ...
7
votes
2answers
478 views
Custom matrix class
It took me while to finish, but here is my custom matrix class. I assume that the row/column iterators are the most critical part of this class but anyway I would very much appreciate your ideas of ...
8
votes
1answer
79 views
Returning multiplied matrix array
Is there a more clever way of writing this piece of code? It does work but I thought there might be a better way of returning a matrix from multiplying the parameter by itself.
...
10
votes
2answers
138 views
Enter the Matrix
I've semi-often been frustrated at the lack of a proper Matrix data structure in VBA. A multi-dimensional array is obviously the right way to handle it, but there is so much missing... for example, ...
4
votes
1answer
69 views
Speeding up nested for-loop analysis code
I have two matrices, the first one is mat 2000*500, the second one is 6000*500 ...
2
votes
2answers
104 views
Rotating contents of a matrix (vector<string>) to the left or right
Each vector element is a row and each character is a column.
Assume the matrix is square (N*N) and N is < 10.
I have some code to do it but it doesn't look great and would love some ...
3
votes
1answer
49 views
Fast counting of interactions between groups given users interactions and groups assignments
Given:
An array c that contains the group assignment of every user (c[i]=4 indicates that user i belongs to group 4)
A matrix ...
3
votes
1answer
99 views
Applying scalar multiplication to matrix
This is one of my first programs in C. Please review and help me improve it. I create a matrix and apply scalar multiplication on it. Then I print the result.
...
1
vote
1answer
38 views
Implementation of Vertex Similarity algorithm (Blondel's Similarity Measure)
I am implementing the vertex similarity algorithm in this paper. The adjacency matrices I will be dealing with, however, will be very large, on the order of 30k vertices (I provided sample matrices in ...
8
votes
3answers
182 views
Matrix reloaded … or reversed
I have written this Matrix class after posting an answer to Malachi's rags-to-riches question. The initial purpose had been to reverse a matrix represented by a 2D ...
6
votes
2answers
134 views
Reversing a Matrix
I took the idea from Reversing a matrix in C# and decided to write my own matrix-reversing code.
Is there anything that I can do to make it even better?
...
2
votes
3answers
125 views
3
votes
1answer
84 views
Immutable Matrix
I'm writing implementations of some numerical methods to solve linear equations systems, those implementations use the following Matrix class. I'm trying to get this class immutable, due to that the ...