DEV Community

Shridhar Shende
Shridhar Shende

Posted on

n-D arrays understanding with real life examples

An n-dimensional array (or n-d array) is a mathematical structure used to represent data organized in multiple dimensions. In computer programming, an array is a structure for storing and retrieving data.

but question rises why do we require n -d arrays in the first place

let’s try an understand with real -life scenario’s

1-Dimesional Array (Vector)

Example: Daily temparatures of a week.
temp_of_a_week = [25, 27, 26, 28, 30, 24, 25]

2-Dimesional Array (Matrix)

2-d array’s is like table

image =
[[ 1, 2, 3],
[ 1, 2, 3],
[ 1, 2, 3]]

dimesions : 3 x 3

e.g. black and white image (grayscale image)

This is the image of the number 7 handwritten dataset from famous MNIST dataset. if you zoom in further the images are getting distorted and small square boxes on the image.

Image description

these small boxes are called as Pixles. Each of these pixels is denoted as a numerical value, and these numbers are called Pixel Values. pixel values denote the intensity of the pixels. For a grayscale or b&w image, we have pixel values ranging from 0 to 255

The smaller numbers closer to zero represent the darker shade while the larger numbers closer to 255 represent the lighter or the white shade.

Image description

every image in a computer is saved in this form matrix of numbers, and this matrix is also known as a Channel.

Image description

this is example is 28 x 28 vlaues of 2-d array

3-Dimesional Array

3-d array are collection of 2-d array’s placed in a queue .

Image description

dimesions = 3 x 3 x 3
e.g. RGB color image

Data: Pixels with three color channels (Red, Green, Blue)

Each pixel has a thee values
like [255,0,0] for red.
[0,0,255] for blue
[255,255,0] for yellow likewise

RGB represents Red, Green and Blue.It is an additive color model.

Image description

Image description

Some more examples of 3-D array:
Medical imaging: MRI scans and CT scans
Computer graphics: 3D models of objects

4-Dimensional Array

4-d array are collection of 3-d array’s .

e.g Video

videos are nothing but collection of images

Image description

Image description

now lets combine these two images to create a video

Image description

remember RGB image is repesented in 3-d array now we have two 3-d array’s placed one above each other.

in computer it can be represented like

Videos represented as 4D arrays (frames, height, width, color channels), where each frame is an image.

Image description

in computer 4-d can be represented in below manner.

Image description

Some more examples:
Video games: game is rendered and player can move around the world
Virtual reality: store the virtual world and user to interact with the virtual world in a realistic way

5-Dimensional Array

5-d array is collection of 4-d array’s.

e.g: In physics and chemistry, simulations of molecular dynamics or quantum mechanics to represent the positions and velocities of particles.

it’s not possible as of now to visulize 5-d data we can only imagine for now.

in computer engineering we can represent something like this.

Image description

Conclusion:
Hope you all now understand how arrays are used in computer to store the data.

Top comments (0)