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
1answer
92 views
C++ Template Matrix Class - WIP
I've created simple matrix class in c++ and I would like to know what you think about the code. I've left the implementation in header file for simplicity for now.
The class is not finished yet, it ...
6
votes
1answer
58 views
Java Matrix multiplication using Multithreading
I am trying to achieve matrix multiplication using the concept of concurrency and cyclic barrier.
Here is the code snippet:-
...
5
votes
1answer
49 views
Find all sub matrices of type N*M in it which are palindromic
Today I had an interview, where I was asked to solve this question.
A \$N*M\$ matrix is called a palindromic matrix, if for all of its rows and columns, elements read from left to right in a row are ...
7
votes
5answers
1k views
Matrices in C implementation
I recently wrote a C implementation of Matrices with add, subtract, and multiply. I want to expand this out eventually where I can diagonalize, efficiently square, row-reduce, etc...
I was wondering ...
2
votes
3answers
50 views
Print diagonal numbers of matrix in ascending order
Today I attempted an interview problem:
Q: An n×n matrix contains numbers from 1 to n×n and is generated in the
fashion:
The first row is of numbers starting from 1 to n left to right, ...
3
votes
1answer
82 views
LeetCode 01: Matrix challenge
Recently, I've solved the "01 Matrix" LeetCode problem and the solution was accepted by the LeetCode OJ:
Given a matrix consists of 0 and 1, find the distance of the nearest 0
for each cell.
...
2
votes
0answers
62 views
Recursive matrix multiplication in C++
I'm working through CLRS, and I'm hoping to get some pointers (ha!) on my C++ coding style and the way I've implemented recursive matrix multiplication. The code right now seems a bit complex for ...
1
vote
1answer
55 views
Matrix OOP implementation using C++11 and C++14
I know that other people already did the same already,
but I'm learning C++ (C++11/14) coming from C (I'm reading Programming: Principles and Practice Using C++, by Bjarne Stroustrup), and this is my ...
7
votes
1answer
97 views
Basic Matrix Class in C++
I've made a simple Matrix class to learn C++. It doesn't use Templates so it only works with int. I made it this way to really understand how to work with objects ...
4
votes
2answers
80 views
Multithread the variant of matrix multiplication
This is matrix multiplication. Big matrix split on the submatrix and multiplication in parallel, result matrices merge to result. How i can make this code better?
...
8
votes
1answer
119 views
Efficient extraction of patch features over an image
Input:
data - a matrix of size n*m*3*3 (complex values)
indices - a list of coordinates (x,y), where x < n and y < m
fp - a feature parameter which is a tuple of ((fp11, fp12), (fp21, fp22)), ...
10
votes
1answer
256 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
87 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
108 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
50 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
1answer
70 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
149 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
61 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
41 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
105 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
157 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
140 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
140 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 ...
4
votes
0answers
84 views
Generalized NumPy reshape function to imitate einsum syntax
I often perform a lot of reshape(), transpose() or squeeze() operations on ...
7
votes
2answers
91 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
42 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
100 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
86 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
150 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
69 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
173 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
134 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
175 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
308 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
105 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
73 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
59 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
47 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
182 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
250 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
68 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
93 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
67 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
66 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
149 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
179 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
256 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
41 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
459 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 ...