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
0answers
16 views
implemente matrix calculation to solve Computational Linear Algebra using Gauss-Jordan Elimination
I am studying (again) Linear algebra and encounter the Gauss-Jordan Elimination. While making program, I notice it use many time to do matrix row swapping.
Thus I make a new matrix template, which ...
10
votes
1answer
126 views
Hackerrank Queen's Attack II
Problem statement
A queen is standing on an \$n\$x\$n\$ chessboard. The chessboard's rows are numbered from \$1\$ to \$n\$, going from bottom to top; its columns are numbered from \$1\$ to \$n\$, ...
6
votes
1answer
80 views
Basic Templated Matrix Library
I am a beginner C++ programmer and I have been working on a library to use for working with matrices. The library main features should be
Working with matrices (addition, subtraction, arbitrary ...
0
votes
2answers
93 views
LSH hashcode generator function
For building an LSH based system in Python, I need to have a very fast calculation of the hashcode.
I won't need to explain here the LSH algorithm itself, but I need help in improving performance of ...
-4
votes
1answer
40 views
Find element in 2D matrix where rows and columns are sorted
Elements of a matrix are given in sorted rows and columns. I want to find the element in an optimized way.
First, I will get the last element of a row, which will determine if a number can exist in ...
1
vote
0answers
54 views
Encryption by transposing text in a grid
I wrote a Java program that given a text message will print the encoded message. The problem is described in this link.
Summary:
We have to write a program that will encrypt a message that do not ...
5
votes
2answers
140 views
Read matrix from file, the C++11/14 way
I am trying to get acquainted with C++11/14, so please tell me if the code below could be written in a more "modern" way. Or, of course, if it could be improved in any way.
The function ...
3
votes
0answers
34 views
Sparse matrix compressed sparse row (CSR) in Python 2.7
Brief introduction for CSR:
The compressed sparse row (CSR) or compressed row storage (CRS) format
represents a matrix M by three (one-dimensional) arrays, that
respectively contain nonzero ...
3
votes
1answer
39 views
Tetris-like algorithm (2D matrix)
The algorithm should be checking if the block fits perfectly when it falls.
The block is always the same shape:
.##....
..##....
Keep in mind I wrote this ...
0
votes
0answers
59 views
Traceback in sequence alignment with affine gap penalty (Needleman-Wunsch)
I am working on an implementation of the Needleman-Wunsch sequence alignment algorithm in python, and I've already implemented the one that uses a linear gap penalty equation for scoring, but now I'm ...
1
vote
2answers
124 views
C++ operator overloading for matrix operations
Please check the code to see if there anything I can improve .
Everyting is working as expected.
matrix.h
...
2
votes
1answer
128 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 ...
1
vote
0answers
109 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).
The algorithm is rated as hard on HackerRank.
On ...
3
votes
0answers
56 views
Generalized NumPy reshape function to imitate einsum syntax
I often perform a lot of reshape(), transpose() or squeeze() operations on ...
7
votes
2answers
88 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
36 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
82 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
60 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
149 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
58 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
96 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
90 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
140 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
277 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
99 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
69 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 ...
2
votes
1answer
55 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
43 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
146 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
177 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 ...
4
votes
1answer
63 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
1k 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
90 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
58 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
60 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
111 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
106 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
124 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
38 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
296 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
88 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
113 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
138 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
96 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
59 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
180 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
253 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
248 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
153 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
131 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
...