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

206 questions
Filter by
Sorted by
Tagged with
2k views

### Verify Eigenpairs

In this challenge, you will be given a square matrix A, a vector v, and a scalar λ. You will ...
575 views

### Lists and arrays, part by part

In this challenge, you'll get four different but somewhat related tasks that must be solved in a specific manner. First, I'll explain the tasks, then follows an explanation of how you must solve it. ...
1k views

Rules No cell range references (A2:B3). Maximum 9 rows and 9 columns. No circular references or formula errors. Empty cells evaluate to ...
3k views

### Robbers: Crack the regex - Make a snake

This is the robber's thread. The cop's thread is here. A snake matrix is a square matrix that follows this pattern: 3-by-3: 1 2 3 6 5 4 7 8 9 and 4-by-4: ...
7k views

### Cops: Make a regex - Make a snake

This is the cop's thread. The robber's thread is here. Write a code that takes an input n and creates a n-by-n "snake matrix". A snake matrix is a matrix that ...
1k views

### Rotating a 2D Matrix

Let's say I have the following (2D) matrix: [[1, 2, 3, 4 ], [5, 6, 7, 8 ], [9, 10, 11, 12], [13, 14, 15, 16]] Rotate the matrix counterclockwise ...
578 views

### Find the submatrix with the smallest mean, 2.0

You're given a n-by-m matrix of integers, where n,m > 3. Your task is to find the 3-by-3 sub-matrix that has the lowest mean, and output this value. Rules and clarifications: The integers will be ...
1k views

### Find the submatrix with the smallest mean

You're given a n-by-m matrix of integers, where n,m > 3. Your task is to find the 3-by-3 sub-matrix that has the lowest mean, and output this value. Rules and clarifications: The integers will be ...
3k views

### Symbolic matrix multiplication

There are lots of different ways to explain matrix multiplication. I'll stick with a single figure since I believe most people here are familiar with it (and the figure is very descriptive). If you ...
634 views

### Construct a Gaussian Matrix

Gaussian blur is a method used for blurring images smoothly. It involves creating a matrix which will be used by convolving it with the pixels of an image. In this challenge, your task is to construct ...
647 views

### Find the rows which make each column have one True (was: Knuth's Algorithm X)

Task Given a Boolean matrix, find one (or optionally more) subset(s) of rows which have exactly one True in each column. You may use any algorithm, but must support very large matrices, like the last ...
997 views

### Turn this array into a matrix

Take a non-nested array as input. Turn it into a matrix by using the following method: Let's say my array is [1, 2, 3, 4, 5] First, I repeat that array 5 times: (...
2k views

### Is it a stochastic matrix?

A stochastic matrix is a matrix of probabilities used in the context of Markov chains. A right stochastic matrix is a matrix where each row sums to 1. A left ...
2k views

### Do Matrix Multiplication!

In mathematics, matrix multiplication or the matrix product is a binary operation that produces a matrix from two matrices. The definition is motivated by linear equations and linear transformations ...
459 views

### Code golf a random orthogonal matrix

An orthogonal matrix is a square matrix with real entries whose columns and rows are orthogonal unit vectors (i.e., orthonormal vectors). This means that M^T M = I, where I is the identity matrix ...
267 views

### Compute the perimeter density matrix

Introduction The perimeter density matrix is an infinite binary matrix M defined as follows. Consider a (1-based) index (x, y), and denote by M[x, y] the rectangular sub-matrix spanned by the corner (...
173 views

### N in a row (or column)! [closed]

N in a row Input: The character and a 2-Dimensional array. The array with a size of N x N where 1 <= N <= 26, it will ...
430 views

### Totally Invertible Submatrices

(inspired by this question over on Math) The Definitions Given an n x n square matrix A, we can call it invertible if there ...
15k views

### Where's the 0xBEEF?

This challenge was inspired by this Wendy's commercial from 1984. Illustration by T S Rogers Your task is to find a hexadecimal 0xBEEF on a binary bun. The 'beef' consists of the following pattern: ...
4k 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 ...
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 ...
510 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 ...
470 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 ...
380 views

### Generate binary matrices which are distinct up to reflections

Here are all the 2x2 binary matrices ...
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: ...
6k 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 ...
466 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 ...
837 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 ...
431 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 are ...
934 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 "...
2k views

### Matrix Trigonometry

Introduction The two most common trigonometric functions, sine and cosine (or sin and ...
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 ...
787 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 ...
872 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 ...
788 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 ...
172 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. ...
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 ...
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 ...
933 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 ...
712 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 ...
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 ...
1k 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 ...
643 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 4 ...
671 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 ...
1k views

### Vandermonde Determinant

Given a vector of n values (x1,x2,x3,...,xn) return the determinant of the corresponding Vandermonde matrix. This determinant ...
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, ...
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: ...
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 <...