# 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.

690 questions
Filter by
Sorted by
Tagged with
98 views

### Determinant of matrix Python

This is an addition of my previous question Python matrix class. I've added a determinant function using Laplace expansion to my Matrix class. What I am looking for specifically is how 3x3 matrices ...
1k views

### Python matrix class

To prepare for my studies in linear algebra, I've decided to write a simple matrix class. This is the initial program, with functions to find the determinant and decomposition(s) to follow. I wanted ...
877 views

### Snail matrix in Java

(This post has an continuation: Snail matrix in Java - version II.) Inspired by this post, I decided to solve that problem in Java. The idea is to decide on an $n \in \mathbb{N}$, create a square ...
1 vote
65 views

### Vectorized code to find the position and length of runs of 1s in a bit matrix

I'm trying to write something like an adjusted run-length encoding for row-wise bit matrices. Specifically I want to "collapse" runs of 1s into the number of 1s in that run while maintaining ...
174 views

### Snail matrix in Java - version III (generalizing)

Once again, in the previous version, Alexander Ivanchenko helped me with his awesome answer. Now, I have improved the toString() and, also, generalized the class ...
2k views

### Create a snail matrix

Statement: Create a script that, given an integer $n$, create a square matrix of dimensions $n \times n$ with the numbers from $1$ to $n^2$, arranged in a snail pattern. Example: ...
328 views

### Snail matrix in Java - version II

(This post is the continuation of Snail matrix in Java. Also, this post has an continuation.) As previously, a snail matrix is any square matrix $M_n = \mathbb{N}^{n \times n}$ with cell elements ...
3k views

### Pad a ragged multidimensional array to rectangular shape

For some machine learning purpose, I need to work with sequences with different lengths. To be able to process efficiently those sequences, I need to process them in batches of size ...
64 views

### Optimizing even more a C++ matrix class with expression templates using variadic templates

I looked at Bowie Owens' cppcon 2019 talk (the slides can be found here) where he shows how to implement a tridiagonal matrix classes using expression templates but without resorting to the CRTP. (It ...
174 views

### Matrix Factorisation class packaging methods for factorisation of explicit & implicit data matrices using Gradient Descent, SGD and ALS

Attached below, and also as this GitHub gist, is code for a Python class I wrote as part of a personal learning/portfolio project on collaborative-filtering recommender systems via matrix ...
457 views

### Image Rotation and Transpose Functions Implementation in C++

This is a follow-up question for Gaussian Fisheye Image Generator Implementation in C++ and An Updated Multi-dimensional Image Data Structure with Variadic Template Functions in C++. I am trying to ...
1k views

### Minimum number of moves to solve "game of fifteen"

I read about this game and tried to make my own algorithm to solve this. I asked it on StackOverflow for the appropriate algorithm and logic to solve this problem. With the help of answers over ...
134 views

I'm working on 2-D top-down graphics engine, and need a way to simulate clouds. My idea was that I could create a layer comprised of a matrix of rectangles whose alpha value would be picked from a ...
410 views

### Cosine similarity calculation in Rust, which is slower than NumPy

I'm running this in release mode. Currently, the following function takes around 6.7 seconds to run on my computer vs 3.7 seconds on Python. I know that Numpy is just calling to C, but I'm trying to ...
462 views

### High Performance Matrix Multiplication is not very high speed, why?

I would appreciate a review of the following Rust implementation of high performance matrix multiplication. After reviewing available literature, including Anatomy of High Performance Matrix ...
305 views

### AVX2 8x8 Float Matrix Multiply in Rust

I'm interested in a fast 8x8 32-bit float matrix multiply in Rust, assuming availability of AVX2. After learning about the AVX2 intrinsics, here is what I came up with: ...
77 views

### Transpose matrix in ANSI C

Is there a way to transpose a matrix in ANSI C way much better than this ANSI C code? Can I do transpose in a different and ...
1k views

### Find Passable Lanes in Rows and Columns

I have implemented the following question and looking forward for the reviews. Question Explanation : We have a two-dimensional board game involving snakes. The board has two types of squares on it: +...
1k views

### Matrix Class Implementation

I have written a minimal matrix class. I would like to utilize the latest C++ features, follow best practices, and utilize multi-threading in some of the operations. I have also setup a GoogleTest ...
678 views

### Determinant calculation of a matrix of any degree

My program calculates the determinant of a matrix of any degree. If you really can't understand my comments or indentifiers please let me know. ...
14 views

### Creating a matrix or matrices for positioning squares on screen

The following implements a mix of hard-code (manual pick and choose) and abstracted solution for creating and placing some squares on screen using different matrix patterns for positioning. Each ...
22 views

### Efficiently computing a batch of results given a batch assignment vector and series of corresponding matrices

I have a 1D tensor of tokens that belong to different batches. The batch sizes here are uneven. Each batch needs to be multiplied with a corresponding weight matrix. My current approach is using a ...
514 views

### Generic matrix library in Java

I have this repository. The most important source files follow. com.github.coderodde.math.linear.matrix.AbstractMatrix.java: ...
125 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: ...
1 vote
198 views

### A CUDA kernel for a matrix product as outer product vectors

To multiply the matrices A and B using the outer product of vectors, we can express each row of matrix A as a row vector and each column of matrix B as a column vector. Then, we can take the outer ...
815 views

### C++ Bitwise adjacency matrix implementation

I have tried to implement a bitwise adjacency matrix to represent a graph with a fixed number of vertices. Instead of wastefully representing each connection with an integer, 64 connections are ...
1 vote
108 views

### Binary search of 2D matrix

I have written code as below: ...
209 views

### Create classes for matrices, including inheritance

I've been learning C++ on and off, and recently learnt about overloading and templates. I wanted to used these concepts to create classes about matrices using ...
690 views

### Fast BLAS-like matrix multiplication in Rust

I have some matrix multiplication code I am writing for a linear algebra library I'm working on. The goal is to emulate BLAS (and achieve BLAS-like performance) without using a BLAS library, as my use-...
253 views

### C++ Eigen/Mex function to perform two pagewise convolutions on a 3D matrix with a simple kernel

I am trying to accelerate an algorithm where I am computing a 2D variance of many complex matrices stored as pages of a 3D array in Matlab. My implementation uses a Mex function with the C++ Matlab ...
2k views

### Matrix implementation

I am trying to implement an optimal and fast running matrix in C++. I need some review of the code and ideas on how to improve the code quality if it shall be. ...
65 views

### S_n covariance calculation function

I am trying to understand the estimator proposed in ["Multidimensional outlier detection and robust estimation using Sn covariance"][1]. I wrote the code in a basic line-by-line form which ...
90 views

### Speed up a JavaScript function for inverting matrices using Gauss elimination

I wrote this function and I'm interested if it can be sped up by improving the code. The function accepts either column major 1D array or 2D row major array. Maybe there are some obvious JS tricks ...
114 views

### An implementation of Givens method for diagonalising symmetric matrices

So I tried to create a code which aims to diagonalise symmetric matrices via Givens algorithm. The program only works for symmetric matrices, for we know a symmetric matrix is always diagonalisable, ...
408 views

### Reading sparse matrix from binary file

I have binary files containing sparse matrices. Their format is: number of rows int length of a row int column index int value float Reading ...
2k views

### Codewars: N-dimensional Von Neumann Neighborhood in a matrix

Task: For creating this challenge on Codewars I need a very performant function that calculates Von Neumann Neighborhood in a N-dimensional array. This function will be called about 2000 times The ...
527 views

### Matrix-vector multiplication with block-column distribution and MPI_Reduce_scatter

I'm studying MPI and I'm trying to solve the exercise (number 3.5) taken from Pacheco's book Introduction to parallel programming. Essentially the exercise is: Write an MPI program that computes the ...
527 views

### Calculate determinant of a matrix using cofactor expansion

I'm using the following two functions to calculate the determinant of A. Would this code be considered to have an asymptotic time complexity of O(n³)? The recursion is throwing me off, but I think ...
525 views

### 2D Matrix in C++

I wanted to play with a two-dimensional generic data container in C++ and explore different methods of traversals: using closures and iterators. I'd like a review of it. ...
346 views

### How can I optimize double for loop in matrix

I am trying to optimize a function called place_block. It is meant to give the best row, col coordinate in the matrix to place a given block of row and column size. ...
97 views

### Multidimensional array in Java

I have this multidimensional array that generalizes vectors and matrices: com.github.coderodde.util.MultidimensionalArray.java: ...
121 views

### Matrix led 7x10 with arduino

Good afternoon, a few days ago I finished a personal project of a 7x10 led matrix programmed with the ATMEGA328p microcontroller. To control the matrix I use 2 74HC595 shift registers in cascade in ...
1 vote
51 views

### Sparse String Matrix Storage Class C++

Introduction I implemented a class to store a matrix with entries at positions (i,j) that are strings. The matrices I would like to efficiently store in this class have strings as entries and it ...
164 views

### N dimensional array index utility

I created the below class to help working with ND Arrays, mapping based on this question. This will help in implementing the code for handling convolutions. How can I improve upon this? Is there ...
4k views

### Template Matrix Class: implemented some basic functionalities

Basically I have written a matrix class for addition, multiplication and scalar multiplication. I need your review of the class implementation below in terms of efficiency, memory consumption and new ...
688 views

### Immutable matrix class with mathematical methods

This was a homework assignment for a data structures course. The goal was to implement a given interface and the assignment was auto-graded by a system that ran some validation tests. Sadly I did not ...
423 views

### Need for matrix multiplication speed

I need help to make matrix multiplication in C run as fast as possible. On my AMD Phenom(tm) II X6 1090T, my program multiplies two square singe precision 4096x4096 matrices in about 6.9 seconds. ...
6k views

### Matrix multiplication with OpenMP parallel for loop

I tried implementing matrix multiplication with parallel for loop in OpenMP as follows. It runs correctly but I want to make sure if I'm missing anything. How does this determine the number of threads ...