An array, or multidimensional array, is a data structure that organizes elements in rows, columns.
The most common arrays are two-dimensional (2D), which resemble a table with rows and columns, but three-dimensional (3D) and higher-dimensional arrays also exist.
Multidimensional arrays are useful for representing structured data, such as images (2D), volumes (3D), or tabular data.
How do multidimensional arrays work?
The operation of arrays is based on the following concepts:
- Dimensions: Each dimension represents a level of organization (rows, columns, depth, etc.).
- Indices: Used to access the elements of the array. For example, in a 2D array, the first index represents the row and the second the column.
- Memory storage: Multidimensional arrays are stored contiguously in memory, which allows fast access to elements.

The Illusion of Dimensions
We have defined an array as a fixed-size data structure organized in two or more dimensions (2D, 3D, etc.), where we access elements via coordinates (x, y) or [row, column].
int[,] tablero = new int[8, 8]; // An 8x8 array
tablero[0, 5] = 1; // Row 0, Column 5
Everything perfect, wonderful. There’s just one “small” catch. Your computer’s RAM is a continuous line, it doesn’t have rows or columns 🤣.
For you to work with [row, column], the programming language has to perform a trick, linearizing the array.
Generally, this is done by placing the rows one after the other. This is what we call Row-Major Order.
Array Syntax in Different Languages
Although the concept is universal, the syntax varies by language. Next, we’ll see examples in several popular languages.
In C#, multidimensional arrays are declared using brackets.
using System;
class Program
{
static void Main()
{
// Declare a 2D array of 3 rows and 3 columns
int[,] matriz = {
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 }
};
// Access elements
Console.WriteLine(matriz[1, 0]); // Output: 4
}
}
In Java, multidimensional arrays are declared using brackets.
public class Main {
public static void main(String[] args) {
// Declare a 2D array of 3 rows and 3 columns
int[][] matriz = {
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 }
};
// Access elements
System.out.println(matriz[1][0]); // Output: 4
}
}
In Python, multidimensional arrays are implemented as lists of lists.
# Declare a 2D array of 3 rows and 3 columns
matriz = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
# Access elements
print(matriz[1][0]) # Output: 4
In JavaScript, multidimensional arrays are implemented as arrays of arrays.
// Declare a 2D array of 3 rows and 3 columns
const matriz = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
// Access elements
console.log(matriz[1][0]); // Output: 4
Arrays with More Than Two Dimensions
Arrays are not limited to two dimensions. They can have three or more dimensions, which is useful for representing more complex data, such as 3D volumes or time series.
For example, this is what a 3D array would look like in C#
using System;
class Program
{
static void Main()
{
// Declare a 3D array of 2x3x4
int[,,] matriz3D = new int[2, 3, 4];
// Initialize the array
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
for (int k = 0; k < 4; k++)
{
matriz3D[i, j, k] = i + j + k;
}
}
}
// Access elements
Console.WriteLine(matriz3D[1, 2, 3]); // Output: 6
}
}
Sparse Arrays
In the field of numerical computation, we frequently encounter arrays where the vast majority of their elements are 0 or null. This type of structure is called a Sparse Array.
If you use a standard array for this:
- You will waste Terabytes of RAM uselessly.
- You will spend the day processing zeros that add nothing.
For these cases, array arithmetic is not useful. We change strategy. Instead of storing a giant array full of zeros, we store only the values that exist.
There are several ways. Some ideas (without going into much detail, which deserves its own article).
We use a simple list where each element says where it is and what its value is.
[ (0, 5, "Star A"), (99, 20, "Star B") ]
If we search for a coordinate and it’s not in the list, we assume it’s 0 or null.
In languages like Python, it’s common to use dictionaries to simulate sparse arrays.
# Instead of array[1000][500] = 1
galaxia = {}
galaxia[(1000, 500)] = 1
For engineering, formats like CSR (Compressed Sparse Row) are used. We use three compact arrays to compress the row indices.
It’s complex to implement, but allows performing multiplications of gigantic matrices (like those used by Google for its search engine or AI models) in an ultra-efficient way.
