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.
0
votes
2answers
51 views
Code for calculating shortest possible route between two given nodes
Recently I came across this problem , here is an excerpt from it,
Heroes in Indian movies are capable of superhuman feats. For example,
they can jump between buildings, jump onto and from ...
0
votes
1answer
28 views
Code for number of routes possible of the given length between 2 given nodes
Recently I came across this problem , here is an excerpt of it,
It is well known that the routing algorithm used on the Internet is
highly non-optimal. A "hop", in Internet jargon, is a pair of ...
4
votes
1answer
65 views
BFS shortest path
I have the following code to return the shortest path on a matrix from top left corner to bottom right corner, with the option of removing one of wall cells (marked ...
2
votes
1answer
48 views
Internal method to calculate the distance between all nodes in Kruskal's Importance (Driver) Algorithm
I've been trying to reduce the indentation from a method in my code. The solution will probably be unrelated to the language, in this case python, although it may rely on some python specific ...
4
votes
0answers
33 views
Cache conscious SIMD matrix multiply of unsigned integers
The goal of the code review by order of importance (i.e. What I hope to hear from you):
I've verified correctness using a straightforward matrix multiply function though I am open to those who want ...
3
votes
1answer
67 views
Generic matrix type in C++
This snippet is about a generic matrix type. The nice part is that given two matrices with respective entry types, say, of short and ...
2
votes
2answers
65 views
C++ Matrix Multiplication Using Classes
I'm trying to write a C++ multiplication program using classes (for the first time - I usually try to avoid OOP) and am having trouble freeing my memory. What I'd ideally like is a matrix class with a ...
3
votes
1answer
39 views
Calculating how similar two objects are according to a database
I want to calculate how similar two objects are according to a database. However the code is very slow; it takes around 2 minutes to analyze just 3 objects. How can I speed it up? I have tried to ...
6
votes
3answers
685 views
Using a greedy algorithm to find the best path in a 2D array
I'm a student and this is one of my assignments. My professor basically confirmed that my code is correct but all he grades on is if I finished the assignment correctly but not the coding style. I ...
4
votes
1answer
85 views
Multiplying two- or three-dimensional arrays with broadcasting
Background
Disclaimer: Skip if you are not interested in the background. The code is far far simpler than this.
The problem is more about programming than math. Here is the definition of ...
-2
votes
2answers
42 views
Numerical algebra using a Matrix class [closed]
I would like to make a Matrix class. Can any of you help me about this class?
There are two ways:
...
5
votes
2answers
50 views
MPI communicator creation exercise
I'm working on an assignment which entails creating communicators following the diagonals of an n x n process grid. I'm interested to get feedback regarding the correctness of the solution I developed ...
2
votes
2answers
74 views
'Zero out' a matrix using Python
Below is my code for an attempted solution to cracking the coding interview exercise 1.8 written in python 3.5. The problem statement is:
Write an algorithm such that if an element in an MxN ...
8
votes
1answer
67 views
Print matrix diagonals method
I need to print (or store) all diagonals of a matrix. This includes the main diagonal ( { (i,i) | i = 1, 2, ... min(m,n) } ). Then all super and sub diagonals.
For ...
3
votes
1answer
61 views
Rotate Matrix using Python
This is my solution to Exercise 1.7 from Cracking the Coding Interview. I would appreciate any feedback on coding style and algorithm efficiency.
I do know that there is an existing function in ...
1
vote
2answers
33 views
Generate Orders from Matrix and save as CSV
I had a task to create a VBA macros which will take a matrix data set with products in rows and persons as a columns (on intersection we have an ordered qty for each material for each person) and ...
7
votes
2answers
123 views
Converting Data in Rows and Columns to Rows in VBA for Excel
I have a working VBA script for Excel that converts a matrix of data with multiple records in per row to multiple rows with one record per row.
A StackOverflow user told me that the code could use ...
3
votes
1answer
74 views
Exporting a table with header and subheader
I have an array matrix, for example A(3,3), I want to make a table with header names like, ['force','mass','acceleration'], the second row contains the units (subheader), ['N','Kg','m/s^2'], and the ...
3
votes
2answers
79 views
Largest area of identical adjacent matrix elements
Given a 2D matrix find the largest area of identical elements.
Here is my first implementation:
...
7
votes
2answers
136 views
Utility method to view submatrices
I implemented an utility method that is able to view an Array[n, m] in another smaller dimension [k, l], where ...
2
votes
2answers
81 views
Allocate N-dimensional array in C++
I need to allocate n-dimensional arrays of type T, currently I am using the following functions. Is there a better way to do this? Also, ideally I would like to allocate a 1-D array and access that as ...
3
votes
1answer
41 views
Search in sorted matrix NxM
The problem (from Cracking the Coding book):
Given an NxM matrix in which each row and each column is sorted in ascending order, write a method to find an element.
I thought of a modified ...
4
votes
1answer
63 views
Conditional removal of columns in sparse matrix
I have a large dataset (78k instances x 490k features) that is loaded as a scipy.sparse.csr_matrix format. From this dataset I want to filter certain features (i.e. ...
2
votes
1answer
89 views
Pattern searching in 2d grid
This is an interview question which i am trying to solve.
You are given a 2D array of characters and a character pattern. WAP to find if pattern is present in 2D array. Pattern can be in any way (all ...
5
votes
2answers
129 views
Simple matrix class C++14
I created a simple 4x4 matrix class (column-major). I would like it to be efficient and to use C++14's full capabilities. Can I improve it?
...
5
votes
2answers
132 views
Printing an N*N array in the rectangular/circular/spiral fashion
The problem is to print an N*N array and fill it with numbers(starting from 1 at (0,0)) in the rectangular/circular/spiral fashion, going inwards, ending at the N*N value.
Also find and count the ...
4
votes
2answers
117 views
If zero found in Matrix. make entire row & column zero
Problem is - If in an MxN matrix, a zero is encountered, the entire row and entire column should be set to zero.
Example -
8 4 2
2 3 7
1 0 1
9 8 4
...
6
votes
1answer
69 views
Python matrix implementation
I created a simple matrix implementation and would like some critique of it, for example:
Things I could add to make it more useful
Ways I could make it more efficient (for example __pow__ or ref())
...
4
votes
1answer
41 views
Speeding up OpenCL matrix-vector multiplication
So I'd like to get a performance boost above and beyond standard Julia matrix-vector multiply, using my Intel HD Graphics 4000 1536 MB GPU, but I can't do better than an order of magnitude worse ...
3
votes
3answers
68 views
Parse 2D matrix, 2 versions
I'm writing a little C program that computes matrices (for learning purpose). The matrix is fed through arguments in the following form : "{{43,543.324,34},{43,432,87}}"
The user doesn't give the ...
8
votes
2answers
168 views
Implementing a tensor product formula
I would like to use C to implement the following formula:
$$\mathbf S(u,v)=\sum_{r=i-p}^{i}\sum_{s=j-q}^{j}N_{r,p}(u)N_{s,q}(v)\mathbf P_{r,s}$$
Namely,
$$
\left(N_{i-p,p}(u),\cdots,N_{i,p}(u)\...
3
votes
1answer
26 views
Profit sensitivity analysis in base R
Using base R, I've conducted a simple profit sensitivity analysis, i.e. measuring the impact on profit if there is a change in price, variable cost per sale, unit sales or fixed costs assuming that ...
3
votes
1answer
50 views
Pretty print a 2D matrix in C (numpy style)
Works for any 2D matrix represented by a 1D array. Comments and criticism welcome. Also wondering whether the code can be made shorter. It's really messy right now.
...
1
vote
1answer
114 views
Horizontally concatenating the entries of two matrices, and padding with NaNs
I have two matrices a and b that have, on each line, some values (null or not) and then a bunch of zeros at the end.
I want to ...
5
votes
2answers
81 views
Extract the largest value for each day from a matrix
I have a matrix in which the right-most elements are repeated YYYYMMDD dates in descending order, for example:
...
2
votes
1answer
70 views
Predict new ratings for each user based on their pearson correlation with other users
I am new to R and programming. I have a set of ratings for 45000 users and 40 odd movies. I need to predict new ratings for each user based on their pearson correlation with other users. I also need ...
3
votes
1answer
81 views
Counting matrix elements that have “4” or “5” as a neighbor
I have a matrix (500x500) of integers. For each entry, I need to look at its surrounding neighbours (so 8 elements) and determine what the integers are, and run a function on these integers.
Here ...
0
votes
1answer
38 views
Assign values to a matrix based on the location of non-zero elements in another matrix
I have a matrix, A containing ones and zeros. I want to create a new matrix B where the non-zero elements are in the same ...
1
vote
1answer
116 views
Merging two square matrices
I would like to optimize a snippet of code, which uses a multiple nested if statements. I am looking for a formula to make it as a combination of multiple arrays ...
5
votes
1answer
97 views
Java method to make a string representation of a matrix
I have coded this static method for converting a double matrix into a nifty String.
It considers the width of the matrix to be ...
3
votes
1answer
94 views
Print matrix in spiral order
I have a task formulated like this
Please print a matrix in spiral order, clockwise from outer rings to inner rings.
I decided to implement it in Clojure.
...
3
votes
1answer
67 views
Symmetry analysis for atom arrangements in a crystal
For a while now I've been meaning to post some of my Haskell code here so that someone can tell me what parts of the language/base library I've been completely overlooking. This is the first thing I'...
2
votes
0answers
77 views
Find minimum distance in matrix
Challenge URL:
http://acm.scu.edu.cn/soj/problem.action?id=3330
Windy has a matrix A with size N*M which only contains 0 or 1. The
distance between Axy and Apq is: |x-p| + |y-q| Can you help ...
0
votes
0answers
32 views
Finding largest sum of submatrix
I found a way to output the biggest sum of square submatrix, but it should work faster. Can someone suggest a better way?
...
2
votes
2answers
77 views
Print out a Zig-Zag Matrix in Haskell
My task is to code something that prints out this:
This is what I have done so far.
...
1
vote
0answers
54 views
Cuda C Matrix Compression
I am using Cuda to learn and implement a CSR matrix compression algorithm. What can I do better relating to C's best practices?
main.c:
...
0
votes
2answers
144 views
google foo.bar max path algorithm puzzle optimization [closed]
I got a programming puzzle described as follows:
Save Beta Rabbit
Oh no! The mad Professor Boolean has trapped Beta Rabbit in an NxN
grid of rooms. In the center of each room (except for ...
1
vote
0answers
54 views
Get vertical acceleration from rotation vector and accelerometer values
My goal here is to calculate the acceleration towards the ground, which I call "vertical acceleration". This seems to be working OK for the most part, except when there is a lot of rotation going on ...
2
votes
1answer
55 views
Spiral a matrix of size NxN filled with integers from 1 up to and including n^2
I have written a solution in Clojure for the following question:
When starting from the number 1 and adding three numbers on each row
a 3x3 matrix is formed as follows:
...
0
votes
1answer
26 views
C function for copying array into matrix
I want a matrix that can grow dynamically and build up a structure in RAM as input arrives from standard input och terminal (shell). First I tried with a matrix like ...