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.
1
vote
0answers
44 views
HackerRank NCR codesprint: Spiral Message
Problem statement:
https://www.hackerrank.com/contests/ncr-codesprint/challenges/spiral-message
You've intercepted an encoded spy message! The message originated as a
single line of one or more ...
0
votes
0answers
39 views
HackerRank - Matrix Rotation
Problem statement
Given a matrix (up to 300 × 300), rotate each element R steps anti-clockwise along concentric rectangular paths (R up to 109).
In April, 2016, I did the practice using C#, but ...
-3
votes
0answers
16 views
Optimize matlab for loop
I have a large matrix and i want to do an exhaustive recherche, but the look took a lot of time. I can't figure out how to optimise it?
...
3
votes
0answers
34 views
Generalized NumPy reshape function to imitate einsum syntax
I often perform a lot of reshape(), transpose() or squeeze() operations on ...
7
votes
2answers
77 views
Probabilistic Matrix Inspection - Suggested by a paper, implemented by me
I have read this paper and I actually found it interesting.
This is an attempt to implement the proposed algorithm. I would like to know:
Is my algorithm correct by what is discribed in the paper?
...
4
votes
1answer
29 views
Converting state matrices to adjacency matrices to thresholded matrices
I am currently taking part in research utilizing Naked Mole Rats. I am utilizing data analysis techniques to answer the overall question, "Can we detect certain types of naked mole rat behavior ...
4
votes
2answers
61 views
Find diagonal positions for bishop movement
In a chess board, I need to find the diagonals a bishop can move on, and more specifically, the coordinates of those squares. So, given a grid of any size and a position in that grid (expressed in ...
4
votes
1answer
50 views
Compute the XOR of all the elements in the upper left triangular of a square matrix
Given a dimension \$D\$. We generate a \$D\times D\$ matrix with elements that start from \$0\$. For example, if we're given a dimension \$4\$ this is what our matrix looks like:
$$
\begin{bmatrix}...
2
votes
1answer
137 views
Matrix of constrained sums using R
In this post, I asked a question regarding how to create a matrix of integers where elements in each row satisfy a particular property.
The notation in the original post is a bit cumbersome so I ...
2
votes
0answers
52 views
Online Principal Component Analysis with spectral bounds
I have question regarding online PCA implemented in the paper. I am interested in the Algorithm 2. I am not certain if there is a bug in my code can someone confirm if my code is correct? The ...
2
votes
1answer
49 views
Swapping the diagonals of a matrix [closed]
I am required to write a simple matrix program and swap the diagonal.
Given the input
1 2 3
4 5 6
7 8 9
After swapping the diagonal it should be
...
3
votes
3answers
68 views
2D Vector: Loading values from .txt file
I've written a program that runs through a matrix of numbers, ranging from 0 to 2, and stores the results in a 2D vector.
I'm using the values in the 2D vector as the profile for a tile map for a ...
3
votes
1answer
129 views
4x4 matrix implementation in C++
I've been doing some 3D graphics in OpenGL lately and I needed a way to work with 4x4 matrices. My implementation supports the following operations:
Matrix-matrix addition.
Matrix-matrix subtraction.
...
3
votes
1answer
239 views
Building a matrix by applying XOR rules
There is a matrix of \$m\$ rows and \$n\$ columns where each row is filled gradually. Given the first row of the matrix we can generate the elements in the subsequent rows using the formula:
$$\begin{...
0
votes
2answers
94 views
Calculating shortest possible route between two given nodes
I recently came across this problem:
Heroes in Indian movies are capable of superhuman feats. For example,
they can jump between buildings, jump onto and from running trains,
catch bullets with ...
0
votes
2answers
64 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
236 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
54 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
41 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
80 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
102 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
57 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
830 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
89 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
46 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
54 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
90 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
74 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
85 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
35 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
185 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
81 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
101 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
137 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
87 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
53 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 version ...
4
votes
1answer
99 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
152 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
181 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
139 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
125 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
87 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
63 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
150 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
172 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
27 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
56 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
116 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
83 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
74 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 ...