# Questions tagged [matrix]

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.

568 questions
Filter by
Sorted by
Tagged with
586 views

### Vector/matrix class

Some definitions: ...
2k views

### Matrix: Set a row/col to zero

A practice interview question: Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0. ...
120 views

### Implementation of Vertex Similarity algorithm (Blondel's Similarity Measure)

I am implementing the vertex similarity algorithm in this paper. The adjacency matrices I will be dealing with, however, will be very large, on the order of 30k vertices (I provided sample matrices in ...
1k views

### Test whether or not a 4x4 matrix is a magic square

Here is what I have. I have it outputting most of the sums just so I can check there values. I think the problem is with the value of the elements in the array storing the column sums. I would greatly ...
1k views

### MaxSum sub matrix within a matrix

Code review for best practices, optimizations, code cleanup etc. Also requesting verification of the complexity: O(row*row*col). ...
222 views

### Rotate matrix clockWise and counter clockWise

This code is a mix of the same question one time rotating to the right and one time to the left. I tried to simplify the code since I'm struggling with all of the indexing here. https://leetcode.com/...
57 views

### Lambda based matrix

I am calling matrix implemented with a lambda "lambda matrix". The full working program: ...
89 views

### Minimum steps to reach target by a Knight In Scala

Given a chessboard of N size (square matrix), the position of Knight and position of a target, find out minimum steps (both count and exact steps) from start to target for a Knight. If it is not ...
2k views

### Basic beginner's matrix class in Python

This is my first class. I've been working a while on it, some functions are future ideas and are right now just bare bones and intended to be worked on later. I'm really looking for a good review of ...
142 views

### Get column of a matrix python with index operator

How can I refactor this code to generalize the argument parsing? I feel like this code can be better but I can't find a way. The usage syntax of the index operator is similar to the NumPy indexing ...
4k views

### Generating a word bigram co-occurrence matrix

I have written a method which is designed to calculate the word co-occurrence matrix in a corpus, such that element(i,j) is the number of times that word i follows word j in the corpus. Here is my ...
361 views

### Fast affine transformations of many 3D points by one 3×4 matrix

I wrote a function to batch-transform 3D vectors by a single 3x4 matrix using SSE2: ...
266 views

### Map square coordinates in matrix to flat array indices without hurting performance

I'm more like playing and the problem I'm going to demonstrate is a learning task, so to speak, not something I really need to solve. Imagine having a matrix of data. You chose square in it and ...
53 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 ...
729 views

### Reading a CSV file containing a dataset of 8×8 images

I am trying to implement a machine learning algorithm (k-nn for example). But before I attempt to do that I was hoping for some feedback on my current Main class, which essentially builds 8×8-pixel ...
797 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 ...
116 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. ...
407 views

### Optimize matlab triple for loop

I have a large matrix samples, I want to make another matrix sampleProb which is the same size, but modified as below: ...
5k views

### Searching for an element in a 2D array

For example, given a 2D array (a matrix): {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}} What are the solutions to find a number, such as 6? Here's the code I ...
1k views

### Computing the sum of squared differences

About Data: 3D data (100x100x20). Computation/Formula and Method: I am trying to compute the sum of squared differences along rows, columns and angles for various time differences. ...
2k views

### Matrix bottom left to top right

Can someone please review this simple code for printing all paths in a matrix from bottom left to top right? If an element is 1, it is a "wall" and you cannot take it. Possible steps: up and right <...
20 views

### R solution to max product in matrix for four adjacent numbers (Euler 11)

Background This is solution to Problem 11 on Project Euler that is concerned with finding largest product of four adjacent numbers in the provided grid. Other than solving the problem I was also ...
140 views

### Fast matrix transpose

I would like to improve the naive matrix transpose algorithm by using a cache friendly algorithm. So far there are 4 variants. Iterate over the source matrix: ...
42 views

### Stochastic gradient descent - backpropagation over mini-batches in one go

I have been working through a tutorial on neural networks. I have then been translating the code to java, to help improve my understanding of what the code is doing. The book mentions a way of ...
75 views

### Convert a type u16 number to a matrix (Vec<Vec<u8>> or array) of 4 x 4

I am a Rust newbie and I am not familiar with all the iterator options. This is what I have so far. How can I make this better or at least avoid collecting twice into a Vec? ...
63 views

### Extract numerics from matrix A with logical matrix B

I have a matrix A containing numeric values and a matrix B containing 0/1s: ...
1k views

### MIPS Assembly Program to access elements in the 4x4 matrix, row or column-major oder

This MIPS Assembly program will make you access the elements in the 4x4 matrix in either row or column-major order i.e. accessing all elements row by row or column by column. Output is posted below ...
127 views

### Performing FFTW double[2] on images of type cv::Mat

I've two different types of variables: cv::Mat and array of type double[2] so I do quite lot of copying between the two types. I ...
54 views

### product member of CSC matrix class

I'm implementing a CSR and CSC class! I found a lot of algorithms for computing a CSC * vector product but I didn't find any routine for the CsC * CsC matrix product, in order to save time when the ...
2k views

### Parallel matrix multiplication in Java with streams

This StackOverflow post highlights how to do matrix multiplication using Java's stream. With Java streams, there is a new way to enable concurrent threading with the Java's parallel stream. ...
204 views

This program is used to solve Challenge #140 [Intermediate] on /r/dailyprogrammer. The challenge is, given a input set of directed edges, print the corresponding ...
48 views

### Blurring an image using matrices

Suppose there is a very big matrix and and a small window is moving on the matrix. The small window will move right and down, step by step (means each time move one step right, or move one step down). ...
3k 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 ...
128 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: ...
412 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 ...
132 views

### Why does lu-factorization make my program slower?

I'm trying to calculate the smallest eigenvalue of the matrix A by using the "inverted exponentiation method" (see the code). I manage to find the smallest eigenvalue, but when I try to optimize the ...
1k views

### Is my 4x4 matrix multiplication on a 1D float array correct?

I'm trying to develop my own math library to use on a Voxel engine, but I'm worried about Matrices multiplication. Everywhere I saw people using 4x4 Matrices on a 2D Float Array but I'm using a 1D ...
34k views

### Matrix operations using classes

So I recently had a practical exam in which I was told to execute a function of a menu oriented matrix operation program using classes. The code I made was supposedly wrong as I hadn't used classes ...
205 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 ...
945 views

### Effective Python 2/3 two-dimensional array initialisation

Recently I noticed that the idiomatic python two-dimensional array initialisation is extremely slow. I am wondering, is there a good, proper way of doing this simple task fast? Also, are those two ...
98 views

### Matrix arithmetic operations

I am currently attempting to implement Matrix Math for another project I am working on. However, I am not sure whether this implementation will work. Can someone please tell me if there are any ...
1k 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 ...
242 views

### Multiplication of 3×3 and N×N square matrices

I recently wrote a matrix module in C++. During the development process I quoted some source code and found a problem. For example, matrix multiplication: This way is suitable for all N×N matrices： ...
115 views

### Multiplying two arrays

I would like to ask how I can make my code more simple and effective. I know that this code can be 100% better. I am supposed to load number for each array and then take the 2 arrays (4*3 and 3*4) and ...
249 views

### Drawing concentric circles to console

This prints out a triple layer circle with 12 points per circle and finds the points across a grid. I had a really hard time with this and I'm planning to implement a lot more code but I don't want ...
547 views

### Calculate median of a matrix

I am solving interview questions from here. Problem : Given a N cross M matrix in which each row is sorted, find the overall median of the matrix. Assume N*M is odd. Note: No extra memory is ...
2k views

### Simple Matrix Rotation

I needed to rotate a non-square matrix in my program to transpose some spreadsheet data and decided to make a function to rotate 90, 180, or 270 degrees. It doesn't rotate the matrix in place, but ...
747 views

### Comparing rows of a matrix with some row vectors

I have run this program for five hours and it has not yet completed. I wonder if we can make changes to reduce the computation time. I use several for loop and this greatly increases the computation ...