Current Level 0: NUMPY Level-0
0 / 6 Miles
0 / 5 Assignments
0 / 5 Exams

📖 Course Miles: Passed Failed Pending Not Attempted Scroll to see all miles (6)

Mile 3: NumPy Arrays & Core Concepts

🎬 YouTube Videos

No YouTube videos available

Check back later for new YouTube content.

📹 Library Videos

NumPy Arrays & Core Concepts

📚 Content

SECTION 1 UNDERSTANDING THE NUMPY NDARRAY

3 min read

Goal
Understand what a NumPy array is and why ndarray is the central object in NumPy.

What Is an ndarray?
The main data structure used by NumPy is called an:

ndarray
ndarray means:
N-dimensional array

The letter N means that the array can have any number of dimensions.
For example, NumPy can represent:

  • Single value
  • List of values
  • Rows and columns
  • Stacks of rows and columns

using the same fundamental array structure.


Example :

import numpy as np
arr = np.array([10, 20, 30, 40])
​​​​​​​print(arr)

Output :

[10 20 30 40]

Here:
np.array(...)
creates a NumPy ndarray.

What Is Inside the Array?
The array contains four elements:

  • 10
  • 20
  • 30
  • 40

Visual representation:

┌────┬────┬────┬────┐
│ 10 │ 20 │ 30 │ 40 │
└────┴────┴────┴────┘

Each value is called an element.

Why Is ndarray Important?
Almost everything we do later in NumPy involves an ndarray.

We will:

  • Create arrays
  • Access array elements
  • Filter arrays
  • Reshape arrays
  • Combine arrays
  • Perform calculations
  • Calculate statistics
  • Work with matrices

Real-World Example :
A NumPy array could represent daily temperatures:
temperatures = np.array([28, 30, 29, 31, 32])

or student marks:
marks = np.array([78, 82, 91, 69, 88])


Common Beginner Mistake
A NumPy array and a Python list can look similar:

[10, 20, 30]


but they are not the same object.


Python list:

data = [10, 20, 30]

NumPy array:

data = np.array([10, 20, 30])

They behave differently during numerical calculations.


Try It Yourself
Create an array containing:

5, 15, 25, 35, 45

and print it.

Key Takeaway
The ndarray is NumPy's main data structure for organizing numerical data into one or more dimensions.

Sign up or sign in to rate this section
SECTION 2 ARRAY ELEMENTS POSITIONS AND STRUCTURE

3 min read

Goal
Understand that NumPy arrays are collections of elements arranged in organized positions.

What Is an Array Element?
Every value stored inside an array is called an element.

Example:

  • arr = np.array([10, 20, 30, 40])

The elements are:

  • 10
  • 20
  • 30
  • 40

Elements Have Positions

Visualize:
Position:     0     1     2     3

            ┌────┬────┬────┬────┐
Array:      │ 10 │ 20 │ 30 │ 40 │
            └────┴────┴────┴────┘

NumPy uses zero-based indexing, just like Python.

  • The first element is position 0.
  • The second element is position 1.

We will study indexing properly in Mile 5, but it is important to understand the idea now.
Arrays Organize Related Data


Consider student marks:
marks = np.array([75, 82, 91, 68])

Rather than thinking of four unrelated numbers,
think:

Student marks dataset
        ↓


75   82   91   68

The values belong to one logical numerical structure.

Ordered Data Matters
The location of an element can have meaning.

For example:
temperatures = np.array([28, 31, 30, 29])

could represent:

  • Monday     → 28
  • Tuesday    → 31
  • Wednesday  → 30
  • Thursday   → 29

Changing the order could change the meaning of the dataset.

Real-World Uses
Array elements can represent:

  • Student scores
  • Daily sales
  • Temperatures
  • Product prices
  • Sensor readings
  • Distances
  • Financial returns

Mini Check
For:

[100, 200, 300, 400]

How many elements are present?
Answer: 4

Key Takeaway
A NumPy array is an organized collection of elements, and the position of each element can carry meaning.

Sign up or sign in to rate this section
SECTION 3 SCALARS AND 0D ARRAYS

3 min read

Goal
Understand the simplest possible NumPy array: a zero-dimensional array.

What Is a Scalar?
A scalar is a single value.

Examples:

  • 10
  • 3.14
  • 100

A scalar does not naturally have rows or columns.

Creating a 0D NumPy Array

import numpy as np
arr = np.array(10)
​​​​​​​print(arr)

Output :

10

This creates a 0-dimensional array.


Visual idea:

┌────┐
│ 10 │
└────┘

It represents one value.


Why Is It Called 0D?
Because there is no array direction to move through.
There is:

  • No row of multiple values
  • No column
  • No table
  • No stack

It is just one scalar value represented as a NumPy array.

Example :

temperature = np.array(28.5)
print(temperature)

Output :

28.5

This can represent one temperature measurement.


Real-World Uses
A 0D value could represent:

  • One temperature
  • One price
  • One measurement
  • One calculated result
  • One model score

Important Beginner Note
Students will encounter 0D arrays less frequently than 1D and 2D arrays in beginner work.
However, understanding them helps build the complete concept:

  • 0D → one value
  • 1D → sequence
  • 2D → table
  • 3D → stack of tables

Quick Question
Which is a scalar?

  • A. [10, 20]
  • B. 10

Answer: B

Key Takeaway
A 0D array represents a single scalar value.

Sign up or sign in to rate this section
SECTION 4 UNDERSTANDING 1D ARRAYS

2 min read

Goal
Understand one-dimensional NumPy arrays and how they represent sequences of values.

What Is a 1D Array?
A one-dimensional array contains values arranged along a single direction.

Example:

arr = np.array([10, 20, 30, 40])
​​​​​​​print(arr)

Output :

[10 20 30 40]

Visual representation:

  • 10 → 20 → 30 → 40

or:

┌────┬────┬────┬────┐
│ 10 │ 20 │ 30 │ 40 │
└────┴────┴────┴────┘

There is one dimension along which the values are arranged.

Example — Student Marks :

marks = np.array([78, 85, 92, 70, 88])
​​​​​​​print(marks)

Output :

[78 85 92 70 88]

This array could represent marks for five students.

Example — Daily Sales :

  • sales = np.array([1200, 1450, 1320, 1600, 1750])

Each value could represent one day's sales.
1D Arrays Are Extremely Common

They are useful for:

  • Prices
  • Marks
  • Measurements
  • Ages
  • Temperatures
  • Quantities
  • Distances
  • Time-series values
  • Think Visually

ONE DIRECTION

→ → → → →
10 20 30 40 50

Predict the Output :

arr = np.array([5, 10, 15])
​​​​​​​print(arr)

Output :

[ 5 10 15]

Try It Yourself
​​​​​​​Create a 1D NumPy array containing:
100, 200, 300, 400, 500

Key Takeaway
A 1D array stores values along one dimension, similar to a numerical sequence.

Sign up or sign in to rate this section
SECTION 5 UNDERSTANDING 2D ARRAYS

3 min read

Goal
Understand arrays containing rows and columns.

What Is a 2D Array?
A two-dimensional array organizes values into:
Rows and columns

Example:

import numpy as np
​​​​​​​arr = np.array([
    [10, 20, 30],
    [40, 50, 60]
])
print(arr)

Output :

[[10 20 30]
 [40 50 60]]

Visual Representation

         Columns
          ↓   ↓   ↓
       ┌────┬────┬────┐
Row 1  │ 10 │ 20 │ 30 │
       ├────┼────┼────┤
Row 2  │ 40 │ 50 │ 60 │
       └────┴────┴────┘

There are:

  • 2 rows
  • 3 columns

Example — Student Marks :
Suppose three students have marks in three subjects.

marks = np.array([
    [80, 75, 90],
    [65, 70, 68],
    [92, 88, 95]
])

Conceptually:

Student    Math    Science    English
Student 1    80    75    90
Student 2    65    70    68
Student 3    92    88    95

This is naturally represented by a 2D NumPy array.

Example — Sales :

             Product A   Product B   Product C


Store 1         100         200         300
Store 2         150         250         350

Again:
Rows represent one type of entity.
Columns represent another type of measurement.

Why 2D Arrays Matter
Many real datasets are naturally table-like:

  • Students × Subjects
  • Stores × Products
  • Days × Measurements
  • Employees × Metrics
  • Machines × Sensors

Common Beginner Mistake
Do not think:
2D means the array must look visually like a physical table in every problem.
The important idea is that the data has two independent directions/dimensions.

Try It Yourself
Create:

[
 [1, 2],
 [3, 4],
 [5, 6]
]

and print it.

Key Takeaway
​​​​​​​A 2D NumPy array organizes values using rows and columns.

Sign up or sign in to rate this section
SECTION 6 UNDERSTANDING 3D ARRAYS

3 min read

Goal
Understand how NumPy extends rows and columns into a third dimension.

What Is a 3D Array?
A 3D array can be visualized as:

A stack of 2D arrays

Start with one 2D array:
[ [1, 2],
  [3, 4] ]

Now imagine another:
[ [5, 6],
  [7, 8] ]

Stack them together:

arr = np.array([
    [
        [1, 2],
        [3, 4]
    ],
    [
        [5, 6],
        [7, 8]
    ]
])

Visual Concept :

Layer 1
1   2
3   4
Layer 2
5   6
7   8

Together:

Layer 1
   ↓
Layer 2

This creates a third dimension.
Real-World Example — Image Data

A color image can conceptually use dimensions such as:
Height × Width × Color Channels


Example:

Pixel rows
   ×
Pixel columns
   ×
RGB channels

Another Example :
Imagine sales data for:
Months × Stores × Products
That naturally requires three dimensions.


Example concept:

January
    Store 1 → Product sales
    Store 2 → Product sales

February
    Store 1 → Product sales
    Store 2 → Product sales


Do Beginners Need to Master 3D Now?
No.

At this stage students only need to understand:
3D = multiple 2D structures organized along another dimension.

Advanced manipulation comes later.


Key Takeaway
A 3D array can be visualized as a stack of 2D arrays.

Sign up or sign in to rate this section
SECTION 7 DIMENSIONS AXES ROWS COLUMNS AND DEPTH

3 min read

Goal
Build a clear visual understanding of the directions available inside NumPy arrays.
This Section is very important before later topics such as shape, axis, broadcasting, and aggregation.

Understanding Dimensions
Consider:

0D → One value
1D → One sequence
2D → Rows + Columns
3D → Layers + Rows + Columns
0D
10

No direction.

1D
10   20   30
→    →    →

One direction.

2D
       Columns →


       10  20  30
       40  50  60
       ↓
      Rows

Two directions.

3D

Conceptually:

Depth / Layers
      ↓
Layer 1
10 20
30 40
Layer 2
50 60
70 80

Three directions.

What Is an Axis?

  • An axis is one direction inside an array.
  • At this point, students only need the concept.
  • We will later calculate along axes.

For example, in a 2D array there are two axes.
One corresponds to one array dimension and the other corresponds to the other dimension.

Important Learning Rule
Do not memorize:

  • axis 0 always means rows
  • axis 1 always means columns

as an isolated sentence.


Instead think:
An axis represents one dimension of an array.
This will make broadcasting and statistics much easier later.

Visual Summary :

0D
Value

1D
Values

2D
Rows × Columns

3D
Layers × Rows × Columns

Quick Check

Which array has two dimensions?

A.
[10, 20, 30]

B.
[
 [10, 20],
 [30, 40]
]

Answer: B

Key Takeaway:
Dimensions describe how numerical values are organized, while axes represent the individual directions within those dimensions.

Sign up or sign in to rate this section
SECTION 8 REAL WORLD DATA AS NUMPY ARRAYS

4 min read

Goal
Learn how to look at real-world numerical information and decide how it could be represented as an array.
This is where students start developing array thinking.

Example 1 — Daily Temperature
28  29  31  30  32

Best representation:
1D arraytemperatures = np.array([28, 29, 31, 30, 32])

Example 2 — Student Marks

            Math   Science   English


Student 1    80       75        90
Student 2    65       70        68
Student 3    92       88        95

Best representation:

2D array

marks = np.array([
    [80, 75, 90],
    [65, 70, 68],
    [92, 88, 95]
])

Example 3 — Store Sales Across Months

Imagine:

Month
 ×
Store
 ×
Product

This could naturally become:
3D data

Example 4 — Image
A grayscale image can be represented as:

  • Height × Width

A color image commonly requires another dimension representing color information.
This demonstrates why multidimensional arrays are so valuable.


How to Think Like a NumPy User
Whenever you see numerical data, ask:

1. What does each value represent?
Example:

  • Marks?
  • Prices?
  • Sensor readings?

2. How are the values grouped?
Example:

  • By student?
  • By product?
  • By day?

3. How many directions are required?
Then decide whether the conceptual structure is:

  • 0D
  • 1D
  • 2D
  • 3D

or higher


Beginner Challenge

Identify the most natural dimension for each dataset.

Dataset A
45, 60, 75, 90
Answer: 1D

Dataset B
[
 [10, 20, 30],
 [40, 50, 60]
]
Answer: 2D

Dataset C
Multiple images stored together.
Possible representation:
3D or higher depending on the image format and batch structure.


Mile 3 Mini Practice

Create these arrays:

1D
prices = np.array([100, 200, 300, 400])
2D
sales = np.array([
    [100, 150, 200],
    [120, 170, 220]
])
3D
data = np.array([
    [[1, 2], [3, 4]],
    [[5, 6], [7, 8]]
])

Print each array and explain in your own words:

  • What each value represents
  • How the values are organized
  • Why that number of dimensions makes sense

Key Takeaway
NumPy expertise begins with learning to translate real-world numerical data into meaningful array structures.

Sign up or sign in to rate this section

📝 Assignment

Available Assignments
Assignment Pass Mark Duration Actions
NumPy Arrays & Core Concepts
70% 01:00:00

📊 Exam

Available Exams
Exam Pass Mark Duration Questions Actions
NumPy Arrays & Core Concepts
70% 00:30:00 5

💬 Comments & Discussion

Sign up free or sign in to post a comment
Sign up free or sign in
No comments yet

Be the first to share your thoughts!