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.
-5
votes
0answers
27 views
matrix classes to calculate the product of matrix with vector [on hold]
I wrote an class of matrix to calculate the product of matrix with vector,without using the class .
So, there is my program:
...
3
votes
1answer
43 views
Multiplying over a matrix
The below code is a solution I put together for the Project Euler #11 question which asked to find the largest product of 4 numbers of any direction in a matrix (horiz, vertic, and diag all ...
11
votes
1answer
283 views
Balanced Random Assignment in Python
It has been a very long time since I've used Python.
What I'm looking for: I would like to create a 6-by-6 random matrix where each component is either 1 or 2, so that there are 18 ones and 18 twos.
...
4
votes
1answer
56 views
2048 Pythonic Merge Function
This post goes over how I updated my 2048 merge function code from spaghetti code to being somewhat more readable.
Spaghetti Old Code
I incorporated a few techniques from pretty much all of your ...
2
votes
0answers
21 views
Kernel density regression in Julia
Here is a naive implementation of a kernel density regression algorithm in Julia.
The code works, but there is quite a bit of room for improvement though. First, there is not an optimal bandwidth ...
17
votes
6answers
2k 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
2answers
87 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
42 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
46 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
89 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 ...
11
votes
0answers
124 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
63 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:
...
5
votes
1answer
159 views
Matrix rotation algorithm - follow-up
In a response to this post I wrote a solution in Python. It passed all the test cases given, so I would like help making it more pythonic and reducing the almost repeated lines.
Link to the source of ...
3
votes
1answer
168 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
52 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.
...
7
votes
0answers
309 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
96 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
75 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
83 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
159 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
87 views
Sudoku verifier program
I implemented a Sudoku validation program.
Can this be optimized even further in terms of performance?
...
3
votes
0answers
29 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
92 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
62 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
65 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
32 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
67 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
77 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
36 views
0
votes
1answer
55 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
54 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
216 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
324 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 ...
6
votes
2answers
357 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
98 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
80 views
1
vote
3answers
364 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
130 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
192 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
141 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
122 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
138 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
82 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
122 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
77 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
184 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
89 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
\$
...