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.
10
votes
6answers
1k views
2048 merge function
From: Principles of Computing Part 1 Course on Coursera
I got -2 pts on my OWLTEST which uses Pylint for style guide. The error states:
Too many branches (17/12)
function "merge", line 7
...
-3
votes
0answers
23 views
explain matrix creation code [on hold]
Here is the original question where the user asks how to create an empty matrix. One of the answers is the following
...
3
votes
2answers
47 views
JavaScript solution for diagonal difference
hackerrank.com - diagonal difference:
Problem Statement
You are given a square matrix of size N×N. Calculate the absolute
difference of the sums across the two main diagonals.
Input ...
0
votes
1answer
31 views
LeetCode Minimum Path Sum algorithm
I am attempting to solve the Minimum Path Sum algorithm problem and I have a working solution, however there was an unwritten requirement that the algorithm not exceed an unspecified amount of time ...
1
vote
0answers
36 views
Function that reorders the columns of a matrix
The objective: Given an m by n matrix, I have written a function in Matlab that reorders the columns of the matrix to output linearly independent columns; other/redundant columns. Basically, it just ...
3
votes
2answers
85 views
Duplicate the previous input if zero or not a number
I have the following code which duplicates the previous input if any entry is less than zero or NaN, except the first row of a matrix.
Is there any other efficient way to do this without using ...
10
votes
0answers
85 views
C SIMD Matrix Multiplication
I recently started toying with SIMD and came up with the following code for matrix multiplication. I would greatly appreciate if someone with more experience with these things could tell me how far ...
3
votes
1answer
51 views
Plotting 2D histograms from files of matrices in R
I wrote a script to turn a file like this one into a colored 2D histogram:
...
1
vote
0answers
23 views
Calculating OpenGL view matrices
I'd like a little help here calculating the view matrix for OpenGL based on the lookat type function:
...
3
votes
1answer
162 views
Shortest path in image
This code takes an image and detects a global shortest path from the top to bottom row, with the requirement that top and bottom column index be the same. For this, it scans through each element on ...
1
vote
1answer
51 views
4D matrix math library for use with OpenGL
I am trying to create a simple library for C to handle OpenGL matrix operations.
You can see the vec3fscalar here.
...
6
votes
0answers
221 views
Matrix rotation algorithm
Problem Statement
You are given a 2D matrix, a, of dimension \$MxN\$ and a positive integer
\$R\$. You have to rotate the matrix R times and print the resultant
matrix. Rotation should be in ...
5
votes
2answers
86 views
Compute spherical distance matrix from list of geographical coordinates
I've got a list of geographic coordinates ([lat, long]) and want to compute the corresponding matrix of distances. Distance shall be spherical distance in km.
...
3
votes
2answers
71 views
Matrix Multiplication Python — Memory Hungry
Here is a snippet from my python script where I am performing:
a dictionary lookup
a cartesian multiplication of a list of len=500 against a list of len=60,
calculating a cumulative addition for ...
2
votes
0answers
77 views
C# port of data mining algorithm much slower than reference implementation
I was trying to implement the algorithm specified in this research paper (please ignore the math, since it's irrelevant to the question). This algorithm is very basic in formal concept analysis. The ...
3
votes
3answers
69 views
Matrix class with lots of tiny methods
I have been following the advice to make tiny methods that does just one thing and does it well. I also have been keen on reducing or eliminating duplication as much as possible.
But when a very ...
7
votes
4answers
148 views
Matrix struct with random values allocation and deallocation
I've written this code in 2013 or 2014, I think. I've rediscovered it today in one of my folders, made some changes and now I'm left (and my 2013/2014 me as well) wondering how good it looks for other ...
1
vote
1answer
73 views
Sudoku verifier program
I implemented a Sudoku validation program.
Can this be optimized even further in terms of performance?
...
3
votes
0answers
24 views
Project Euler #2 in Go
I just learned Go (yesterday in fact) and today I made this solution to Project Euler #2. The problem is to sum the even Fibonacci numbers. My program uses the matrix representation of the linear ...
3
votes
1answer
86 views
Fast row-wise, parallel calculations on large, sparse matrix
I have a big (50k*150k) matrix with co-occurrences of nouns (rows) and adjectives (columns). As most nouns don't co-occurr with most adjectives, this matrix is very sparse, >99.9%, so I'm using the ...
3
votes
1answer
52 views
Implementation of KNN in R
I have implemented the K-Nearest Neighbor algorithm with Euclidean distance in R. It works fine but takes tremendously huge time than the library function (get.knn). Please point out the possibility ...
3
votes
1answer
56 views
Reimplementing numpy.genfromtxt in Fortran for Python
I've found that the function genfromtxt from numpy in Python is very slow.
Therefore I decided to wrap a subroutine with f2py to read my data. The data is a ...
4
votes
0answers
29 views
Basic declarative style to rotate and crop an image array
I wrote a couple of basic Clojure functions (practicing a declarative style) and I was looking to get some feedback on them. You can see all the code here. Is there anything I could improve on to ...
1
vote
0answers
66 views
A* search algorithm in Clojure
Cost of nodes are represented by a matrix (called world), heuristic cost estimate/g score/f score are all represented in matrices.
The world and its size are ...
2
votes
1answer
69 views
Doing wire 3D cube without libraries
I was having fun implementing some really basic stuff for 3D graphics. See what I came up with:
Matrix.java:
...
5
votes
1answer
113 views
Linear algebra module
I'm working on a linear algebra module to improve my knowledge with mathematics and, because I'll need a lightweight linear algebra module for my future work with Vulkan!
I tried to keep a blas-like ...
3
votes
2answers
34 views
0
votes
1answer
53 views
Find Row with Max zero
To find the row with max zero Matrix will have either 0 or 1 in sorted manner.
...
2
votes
0answers
47 views
Linear System Solver using Gauss-Jordan Elimination
I'm learning about Gauss-Jordan Elimination, and decided to write a program to automate the process to help solidify my understanding. Along with the algorithm itself, I wrote a ...
6
votes
3answers
208 views
Finding clusters in a matrix
I got asked at an interview to write a program that, given a NxM matrix with zeros and ones, prints out the list of clusters of 1s. The clusters are defined as patches of 1s connected horizontally, ...
2
votes
2answers
221 views
Finding paths through matrix
Given the problem:
You are given a 2-Dimensional array with M rows and N columns. You are
initially positioned at (0,0) which is the top-left cell in the array.
You are allowed to move either ...
3
votes
2answers
242 views
Find largest block in matrix
(Largest block)
Given a square matrix with the elements 0 or 1, write a program to find a maximum square submatrix whose elements are all 1s. Your program should prompt the user to enter the ...
3
votes
1answer
92 views
Calculating the determinant of a matrix
I wanted to do some exercise and came up with the idea of a good challenge (for my level of course). I tried to implement Laplace's algorithm for computing the determinant, recursively.
...
5
votes
2answers
74 views
1
vote
3answers
275 views
Adjacency matrix on undirected graph
Please review my Adjacency Matrix class based on this code.
Since I use std::vector to create the matrix, I would like to store as many nodes as possible. Is it ...
5
votes
1answer
111 views
Compute weighted average around a point in a matrix quickly
I have a short snippet of code that simply computes a weighted average for surrounding elements in a square matrix. The actual implementation that I'm working on is not an average (more complex ...
8
votes
1answer
190 views
Parsing equations from stdin
The program should read equations from stdin, parse them and generate a matrix of the coefficient which represents the system.
Example:
...
5
votes
2answers
126 views
D3 Matrix table
I am able to develop this matrix but I think code can be improved. I am creating a map on which each rectangle may have zero through many list items with their titles (still need to add code for ...
2
votes
2answers
95 views
Listing all paths through a matrix, stepping right or down only
I have the following method, which finds all the possible paths from the top left to bottom right of an N x M matrix. I was wondering what is the best way to optimize it for speed as it is a little ...
5
votes
1answer
122 views
Strongly connected components, component graph, semiconnected graph and new graph from SCCs
I have written a program in C to do the following:
Read a matrix (in file format, first line you have the size, then next are the entries). This is done by the "input" function.
Find the strongly ...
5
votes
1answer
80 views
Reading a matrix and computing the determinant
As one of my first C programs I want to read in a matrix and compute its determinant. I don't pose limits on the size of the matrix and this makes things more complicated.
Version 0
...
3
votes
3answers
111 views
Computation of inter-grid distance array for 2D lattice
I have a 2D lattice with U × U number of grids. My goal is to create an array – of shape U^2 × U^2 – where each entry denotes the least-distance between each grid and any other grid.
Currently, for ...
8
votes
1answer
72 views
Ring datatype in Python
I wanted to write something that would be useful for the indices of a grid where if one walked off the edge of the grid they would re enter on the opposite side. This could in theory help with ...
0
votes
1answer
162 views
Eigenvalue calculation for a Java matrix library [closed]
After an interview didn't go smoothly, I decided to write my own library so that I would be better prepared if I'm ever asked about matrix multiplication again.
I know that doing it in Java is going ...
4
votes
1answer
88 views
Large Matrix Square Difference Means
I try to transfere Matlab calculation to C and call it using .mex for speed gains. My goal is to perform for a matrix \$ B\$ which has roughly the dimension 10000x1000
\$
...
3
votes
0answers
47 views
Computing pairwise distance covariances for a symmetric matrix
I wrote a non-vectorized, non-parallel wrapper function for computing the pairwise distance covariances (Wikipedia) (original paper) in a data frame:
...
5
votes
1answer
110 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
107 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 ...
4
votes
2answers
668 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
87 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:
...