# Questions tagged [matrix]

This tag is for challenges involving matrices. A matrix, also known as a 2D array, is a list of numbers arranged in a rectangle with rows and columns.

295 questions
Filter by
Sorted by
Tagged with
3k views

### Create Bernard from Desmos

Background In the online graphing calculator Desmos, there is a certain shape that appears in the lower left portion of the graph in many high detail graphs, which the Desmos community has dubbed &...
1k views

### Matrix with 1 to L(n), in all n columns

Challenge: Take a list, L containing positive integers as input: 3 5 2 1 6 and create a matrix where the n'th column contains the vector 1:L(n), where shorter ...
2k views

### Generate this number table

Given an integer $1 < n < 10$ generate a table like below. For $n = 5$, 1 2 3 4 5 2 2 3 4 5 3 3 3 4 5 4 4 4 4 5 5 5 5 5 5 For $n = 8$, ...
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 ...
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 ...
690 views

### Count the contiguous submatrices

Migrated from chat Given two non-empty non-negative integer matrices A and B, answer the number of times A occurs as a contiguous, possibly overlapping, submatrix in B. Examples/Rules 0. There may not ...
2k views

### Index of the row with most non-zero elements

This is a simple one: Take a matrix of integers as input, and output the index of the row with the most non-zero elements. You may assume that there will only be one row with the most non-zero ...
3k views

### Rebuild a rectangular array from a corner

I once had a beautiful rectangular array. It was very symmetrical, but unfortunately it has fallen apart and now I only have the top left corner. Your task will be to rebuild the original array. Your ...
3k views

### Orthodiagonal steps

It's a common problem to navigate in a 2D matrix. We've seen it many times and will see again. So let's help future us and develop the shortest solutions to generate all eight possible steps in a 2D ...
3k views

### Create a checkerboard matrix

Take a positive integer n as input, and output a n-by-n checkerboard matrix consisting of 1 and 0. The top left digit should always be 1. Test cases: ...
3k 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 ...
7k views

### Generate all square sub-matrices of a given size

You will be given a square matrix of integers M and another positive integer n, strictly smaller than the size of M. Your task is to generate all square sub-matrices of M of size n. For the purposes ...
1k 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: (...
6k 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 <...
3k views

### Check if all non-zero elements in a matrix are connected

Input: A matrix containing integers in the range [0 - 9]. Challenge: Determine if all non-zero elements are connected to each other vertically and/or horizontally. Output: A truthy value if all ...
3k 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 ...
1k 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 ...
4k 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 ...
2k views

2k views

### Reconstruct Matrix from its diagonals

Given the diagonals of a matrix, reconstruct the original matrix. The diagonals parallel to the major diagonal (the main diagonals) will be given. Diagonals: ...