terminal

codeando_simple

terminal

menu

terminal

search_module

guest@codeandosimple: ~/system/search $ grep -r "" .

Press [ENTER] to execute search

Status

Engine: Ready

Database: Online

Index: V2.1.0_LATEST

bash -- cat intro-arrays.md
guest@codeandosimple: ~/intro $ cat intro-arrays.md

Arrays and Matrices_

// "It always seems impossible until it's done" - Nelson Mandela

// The basics

Array (vector, matrix), a type of variable that allows storing more than one value, one of the fundamental tools for programming.

Video thumbnail

# Arrays (Arrangements - Vectors - Matrices)

Previously, we saw that a variable is like a box that stores a value. An array or arrangement is a type of variable that stores a set of values, that is, it has more than one value.

We can see it as a piece of furniture with drawers, a chest of drawers. Each drawer is identified with a position: the top one, the middle one, the last one. If we see it with numbers it could be drawer zero, one, two.

chest of drawers analogy

We can also see it as if they were rows.

array rows

In other words, to access each element of the vector we use an index, the position. I always identify each element of the array with its position, the row.

If we want to access the first value (index zero) chest_of_drawers[0], the second chest_of_drawers[1] and so on.

indexes

Whether to print the value, to see the value, or to change its value.

array assignment

The number of drawers is the number of elements in the vector. length, size, are the ways to access this value, the functions that languages usually bring.

array size

The array, like any variable, is of a data type. It can be an array of integers, an array of decimals, an array of strings.

types in arrays

In this case we saw that we had rows, but we can also have columns of drawers, what is known as a two-dimensional array: matrix.

matrix

Each drawer is now identified with two indexes: row and column. The drawer[0][0], drawer[0][1], drawer[1][0]. I use one index to identify the row and another for the column.

matrix indexes

An array of integers, I assign value to a position, I print the value.

matrix code

The dimension is the number of indexes we need to identify an element. A single dimension is called a Vector; more than one dimension is called a Matrix. The most common is 2 dimensions.

dimensions summary

But there are also 3 dimensions, which we can see as a cube.

3d cube

Anything from 4 dimensions onwards escapes what we can imagine, since our reality is in 3 dimensions, but matrices of more dimensions are also used.

An array is usually identified by its number of elements: we say that a matrix is n by m if it has n rows and m columns, where n and m are any natural number.

n x m

That's as far as we go with the theme of arrays and this introduction to programming. These are the basic themes that a programmer must master, and the only way to achieve it is by practicing. It is not enough to just read theory; doing programming logic exercises is fundamental.

Resources used