The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [matrix]

A matrix is a list of numbers arranged in a rectangle with rows and columns. In programming, it is also known as a 2D array. Use this tag if your challenge is about manipulating matrices.

Filter by
Sorted by
Tagged with
26
votes
9answers
3k views

Calculate the permanent as quickly as possible

The challenge is to write the fastest code possible for computing the permanent of a matrix. The permanent of an n-by-n matrix ...
19
votes
12answers
3k views

Codegolf the permanent

The challenge is to write codegolf for the permanent of a matrix. The permanent of an n-by-n matrix ...
5
votes
5answers
502 views

Image Smoothie!

Input into your program a black and white image. (png, jpg, etc) Convert the image to a 2D matrix of pixels, where each index is the grayscale value of the image. Take each index of the matrix and ...
9
votes
7answers
429 views

Fill in the grid randomly

Given positive integer n < 10, create a 2 dimensional matrix where each location is filled with its x and ...
14
votes
7answers
360 views

Generate binary matrices which are distinct up to reflections

Here are all the 2x2 binary matrices ...
23
votes
16answers
2k views

Create a pyramidal matrix

A pyramidal matrix is a square matrix where all numbers increase or decrease from the center point, like the two matrices below: ...
21
votes
17answers
5k views

Dijkstra's Challenge

Presented in honor of APL as an interactive tool turning 50 this year Background Ken [Iverson] presented his paper Formalism in Programming Languages in August 1963 at a Working Conference on ...
9
votes
6answers
415 views

Index sum and strip my matrix

Index sum and strip my matrix Given a matrix/2d array in your preferable language Input: The matrix will always have an odd length The matrix will always be perfectly square The matrix values can ...
16
votes
9answers
781 views

Alternating sign matrix verification

An alternating sign matrix is an n by n matrix consisting of the numbers -1, 0, 1, such that: The sum of each row and column is ...
10
votes
13answers
368 views

Dot Product of Diagonals

This challenge is very simple. You are given as input a square matrix, represented in any sane way, and you have to output the dot product of the diagonals of the matrix. The diagonals in specific ...
18
votes
5answers
826 views

Jordan Decomposition

Important note: Because this challenge only applies to square matrices, any time I use the term "matrix", it is assumed that I am referring to a square matrix. I am leaving off the "square" ...
13
votes
8answers
1k views

Matrix Trigonometry

Introduction The two most common trigonometric functions, sine and cosine (or sin and ...
11
votes
7answers
1k views

Calculate the Kronecker Product

Related, but very different. In the examples below, A and B will be 2-by-2 matrices, and the matrices are one-indexed. A ...
9
votes
10answers
694 views

Find the Matrix Power

Problem Create a program or function that can calculate the result of a matrix raised to the nth power. Your code will take an arbitrary square matrix A and a non-negative integer n, and return a ...
16
votes
8answers
845 views

Transform a matrix

Write a program or function where a matrix A (maximum value of dimensions of the matrix is 100) is transformed to a new matrix B. Each element of the new matrix B is the sum of the positive neighbors ...
9
votes
6answers
674 views

Calculate the Kronecker sum of two matrices

In the examples below, A and B will be 2-by-2 matrices, and the matrices are one-indexed. A Kronecker product has the ...
4
votes
1answer
170 views

Find the last position in a matrix walking like a spiral [closed]

This question will be deleted soon, do not read/answer it Introduction Given one matrix A x A and a number of movements N. ...
20
votes
15answers
2k views

Diamondize a Matrix

Given a matrix, output a representation of the matrix where the top left element is on top, the anti-diagonal is the central row and the bottom right element is at the bottom. For example, consider ...
15
votes
18answers
1k views

Sorting rectangular matrices

Given a matrix A, we can say that it is "sorted" if each row and column of A is sorted (ascending left-to-right for rows and top-...
19
votes
7answers
765 views

Hilbert-Curvify a Matrix

Inspired by this question Another way to unroll a 2D image into a 1D string is to use an Hilbert Curve. There are many version of this curve, depending on the number of iterations used while ...
18
votes
3answers
667 views

Reconstruct a zigzagified matrix

As part of its compression algorithm, the JPEG standard unrolls a matrix into a vector along antidiagonals of alternating direction: Your task is to take the unrolled vector along with the matrix ...
43
votes
10answers
4k views

Zigzagify a Matrix

As part of its compression algorithm, the JPEG standard unrolls a matrix into a vector along antidiagonals of alternating direction: Your task is to take a matrix (not necessarily square) and return ...
21
votes
7answers
988 views

Is this a submatrix?

This is the 2-dimensional generalisation of this challenge. For our purposes, one matrix (or 2D array) A is considered a submatrix of another matrix B, if A can be obtained by completely removing a ...
11
votes
3answers
606 views

Rotate every 2x2 block in a matrix

The Challenge Given a n x m matrix with n > 1 and m > 1 filled with integers 1 2 3 ...
15
votes
4answers
568 views

Rotate every row and column in a matrix

The Challenge Given a n x n matrix of integers with n >= 2 1 2 3 4 and a list of integers with exactly ...
25
votes
17answers
981 views

Vandermonde Determinant

Given a vector of n values (x1,x2,x3,...,xn) return the determinant of the corresponding Vandermonde matrix. This determinant ...
17
votes
11answers
1k views

Recursive 2x2 determinant

The determinant of a 2 by 2 matrix a b c d is given by ad - bc. Given a matrix of digits with dimensions 2n by 2n, n ≥ 1, ...
25
votes
14answers
1k views

Fibonacci-style matrix expansion

For each row and then column of a matrix, we can add an extra entry with the sum of the last two entries in that row or column. For example with the following input matrix: ...
43
votes
84answers
5k views

Construct the Identity Matrix

The challenge is very simple. Given an integer input n, output the n x n identity matrix. The identity matrix is one that has <...
16
votes
5answers
640 views

Cofactor Matrices

The cofactor matrix is the transpose of the Adjugate Matrix. The elements of this matrix are the cofactors of the original matrix. The cofactor (i.e. the element of the cofactor matrix at row i and ...
15
votes
12answers
667 views

Construct a companion matrix

You have a number of polynomials who are lonely, so make them some companions (who won’t threaten to stab)! For a polynomial of degree n, there is an ...
8
votes
1answer
1k views

Reduced Row-Echelon Form of a Matrix

The goal of this challenge is to create a program that takes in a matrix and outputs its reduced row-echelon form. A matrix is in reduced row-echelon form if it meets all of the following ...
12
votes
4answers
454 views

Multiply Pauli Matrices

The Pauli matrices are a set of 2x2 matrices which appear very commonly in quantum physics (no, you don't need to know any quantum physics for this challenge). If we include the identity in the set, ...
-3
votes
1answer
463 views

Find the inverse of a matrix

Write a full program to calculate the inverse of a 4-by-4 matrix. Rules The sixteen values of the initial matrix must be hard-coded to variables, as follows: ...
11
votes
3answers
1k views

Solve a 2x2 Eigensystem

For those with a little linear algebra background, the challenge is as simple as this: determine the eigenvalues and eigenvectors of a given complex 2x2 matrix. You may skip ahead to The Challenge for ...
17
votes
10answers
500 views

Ascending matrix

The "ascending matrix" is an infinite matrix of whole numbers (0 included) in which any element is the smallest available element which has not been previously used on the respective row and column: <...
6
votes
9answers
4k views

matrix determinant [closed]

Calculate the determinant of an n x n matrix. Rules read matrix from standard input write to standard output do not use ready solutions from library or language input: columns separated by any ...