NumPy TRB CSI › Python Programming › Numpy

NumPy

NumPy என்பது Python-ல் numerical data-ஐ fast-ஆக process செய்ய பயன்படும் powerful library. NumPy full form: Numerical Python NumPy-ன் முக்கிய purpose: Arrays, matrices, mathematical operations, statistical calculations, scientific computing…

Premium — locked Beginner 40 min 448 cards 145 programs 19 MCQs v2
This is a premium lesson. You can see the shape of every card — unlock to read them. Unlock
Definition

NumPy என்பது Python-ல் numerical data-ஐ fast-ஆக process செய்ய பயன்படும் powerful library. NumPy full form: Nu……

Premium This card is part of the premium lesson. Unlock
Simple Explanation

Normal Python list: numbers = [10, 20, 30, 40] இது multiple values store செய்யும். ஆனால் large numerical data……

Premium This card is part of the premium lesson. Unlock
Flow

Install NumPy ↓ Import NumPy ↓ Create NumPy Ar……

Premium This card is part of the premium lesson. Unlock
Program
Example
Syntax
NumPy import
Syntax
Array creation
Program
Example
Important

Python list output: [10, 20, 30] Num……

Premium This card is part of the premium lesson. Unlock

Why NumPy?

NumPy use செய்வதற்கு முக்கிய காரணங்கள்: Fast numerical calculations Less code Multidimensional arrays Mat……

Premium This card is part of the premium lesson. Unlock
Comparison
Python List vs NumPy Array
Important

Very Important Difference Pyt……

Premium This card is part of the premium lesson. Unlock

List repeat ஆகிறது. NumPy:…

Premium This card is part of the premium lesson. Unlock

ஒவ்வொரு element-மும் multiply……

Premium This card is part of the premium lesson. Unlock

Installing NumPy

Command Prompt / Terminal: pip ins……

Premium This card is part of the premium lesson. Unlock
Important

NumPy Python Standard Library-ன் built-in module அல்ல. ……

Premium This card is part of the premium lesson. Unlock

Importing NumPy

Program
Normal

Use: numpy.array([1, 2, 3]) C……

Premium This card is part of the premium lesson. Unlock

Then: np.array([1, 2, 3])…

Premium This card is part of the premium lesson. Unlock
Memory Trick

NumPy → np Pandas → pd Matplo……

Premium This card is part of the premium lesson. Unlock

NumPy Array

Definition

NumPy-ன் main data structure: ndarray Full form: N-dimensional Array nd……

Premium This card is part of the premium lesson. Unlock
Simple Explanation

1D array: [10 20 30] 2D array: [[……

Premium This card is part of the premium lesson. Unlock
TRB Point

The fundamental array object ……

Premium This card is part of the premium lesson. Unlock

One-Dimensional Array - 1D

A one-dimensional array is li……

Premium This card is part of the premium lesson. Unlock

Two-Dimensional Array - 2D

A 2D array contains rows and ……

Premium This card is part of the premium lesson. Unlock

Rows: [10 20] [30 40] Columns……

Premium This card is part of the premium lesson. Unlock

Three-Dimensional Array - 3D

Conceptually: 2 blocks ↓ Each……

Premium This card is part of the premium lesson. Unlock
Important

Dimensions: 1D → One axis 2D ……

Premium This card is part of the premium lesson. Unlock

ndim

ndim tells number of dimensio……

Premium This card is part of the premium lesson. Unlock
Program
2D
Memory Trick

ndim = Number of Dimensions…

Premium This card is part of the premium lesson. Unlock

shape

Definition

shape tells the size of each dime……

Premium This card is part of the premium lesson. Unlock
Definition
Meaning

3 elements. 2D: a = np.array(……

Premium This card is part of the premium lesson. Unlock
Definition
Meaning

2 rows 3 columns…

Premium This card is part of the premium lesson. Unlock
Memory Trick

shape = Rows and Columns Stru……

Premium This card is part of the premium lesson. Unlock

size

size gives total number of el……

Premium This card is part of the premium lesson. Unlock

Because: 2 rows × 3 columns =……

Premium This card is part of the premium lesson. Unlock

dtype

Definition

dtype tells the data type of NumPy array el……

Premium This card is part of the premium lesson. Unlock
Output
Possible output

or depending on platform: int……

Premium This card is part of the premium lesson. Unlock
Output
Possible output
Important

Exact integer dtype may vary based on pl……

Premium This card is part of the premium lesson. Unlock
Comparison
ndim vs shape vs size vs dtype
Memory Trick

N S S D N → ndim → Number of dimensions S……

Premium This card is part of the premium lesson. Unlock

Indexing in NumPy

Definition

Indexing means accessing an individua……

Premium This card is part of the premium lesson. Unlock
Explanation

Array: [10 20 30 40] Indexes:……

Premium This card is part of the premium lesson. Unlock

Negative Indexing

-1 means last element.…

Premium This card is part of the premium lesson. Unlock

2D Indexing

Definition
Meaning

a[row, column] Here: Row 0 Co……

Premium This card is part of the premium lesson. Unlock
Memory Trick

2D: array[row, column]…

Premium This card is part of the premium lesson. Unlock

Slicing

Definition

Slicing means accessing a rang……

Premium This card is part of the premium lesson. Unlock
Important

start included. stop excluded.…

Premium This card is part of the premium lesson. Unlock

Why? Start index 1 included. ……

Premium This card is part of the premium lesson. Unlock

Slice with Step

Explanation
Syntax

array[start:stop:step]…

Premium This card is part of the premium lesson. Unlock
Program
Example

Change Array Value

NumPy arrays are mutable.…

Premium This card is part of the premium lesson. Unlock
Important

NumPy array is mutable. Exist……

Premium This card is part of the premium lesson. Unlock

Array Arithmetic

This is one of the most impor……

Premium This card is part of the premium lesson. Unlock

5 ஒவ்வொரு element-க்கும் add ……

Premium This card is part of the premium lesson. Unlock
Important

This is called: Vectorized oper……

Premium This card is part of the premium lesson. Unlock

Array-to-Array Operations

Calculation: 10 + 1 = 11 20 +……

Premium This card is part of the premium lesson. Unlock
Important

This is element-wise multipli……

Premium This card is part of the premium lesson. Unlock
Common Mistake

Students may think: a * b does matrix multiplication. Not necessarily. For normal NumPy ar……

Premium This card is part of the premium lesson. Unlock

Mathematical Functions

NumPy provides many mathemati……

Premium This card is part of the premium lesson. Unlock

Aggregate Functions

Aggregate means summarizing m……

Premium This card is part of the premium lesson. Unlock

np.arange()

Definition

np.arange() creates evenly sp……

Premium This card is part of the premium lesson. Unlock
Explanation
Syntax

np.arange(start, stop, step)…

Premium This card is part of the premium lesson. Unlock

Stop value 6 excluded.…

Premium This card is part of the premium lesson. Unlock
Comparison
Python range() vs NumPy arange()

np.linspace()

Definition

linspace() creates a specified nu……

Premium This card is part of the premium lesson. Unlock
Explanation
Syntax

np.linspace(start, stop, numb……

Premium This card is part of the premium lesson. Unlock
Important

linspace()-ல் stop value norm……

Premium This card is part of the premium lesson. Unlock
Comparison
arange() vs linspace()
Memory Trick

arange → Give me the gap / st……

Premium This card is part of the premium lesson. Unlock

np.zeros()

Creates array filled with zer……

Premium This card is part of the premium lesson. Unlock
Program
2D

np.ones()

np.full()

Create array filled with a sp……

Premium This card is part of the premium lesson. Unlock
Program
2D

Identity Matrix - np.eye()

Definition

Identity matrix: Main diagona……

Premium This card is part of the premium lesson. Unlock

Reshaping Arrays

Definition

Reshaping means changing arra……

Premium This card is part of the premium lesson. Unlock
Program
Example
Common Mistake

Wrong: a.reshape(4, 2) 6 elem……

Premium This card is part of the premium lesson. Unlock
Important

Reshape condition: Original n……

Premium This card is part of the premium lesson. Unlock
Memory Trick

Reshape: Total elements must ……

Premium This card is part of the premium lesson. Unlock

Flatten

Convert multidimensional arra……

Premium This card is part of the premium lesson. Unlock

Transpose

Rows become columns and colum……

Premium This card is part of the premium lesson. Unlock
Flow

Original: 1 2 3 4 5 6 Transpo……

Premium This card is part of the premium lesson. Unlock

Concatenation

Join arrays.…

Premium This card is part of the premium lesson. Unlock

Boolean Filtering

This is a very important NumP……

Premium This card is part of the premium lesson. Unlock
Explanation

Condition: a > 25 produces conceptually: Fal……

Premium This card is part of the premium lesson. Unlock

NumPy Comparison

Important

NumPy comparison works elemen……

Premium This card is part of the premium lesson. Unlock

Copy vs View

This is an important advanced……

Premium This card is part of the premium lesson. Unlock

Original remains unchanged.…

Premium This card is part of the premium lesson. Unlock

Because view shares underlyin……

Premium This card is part of the premium lesson. Unlock

Sorting

Searching

Program
Example using where()
Output
Possible output
Definition
Meaning

20 appears at indexes: 1 and 3…

Premium This card is part of the premium lesson. Unlock

Random Numbers in NumPy

Modern NumPy commonly uses ran……

Premium This card is part of the premium lesson. Unlock
Program
Example
Output
Possible output
Definition
Meaning

5 random integers.…

Premium This card is part of the premium lesson. Unlock
Important

Because values are random, ou……

Premium This card is part of the premium lesson. Unlock

Matrix Addition

Matrix Element-wise Multiplication

Calculation: 1×5 2×6 3×7 4×8…

Premium This card is part of the premium lesson. Unlock

Matrix Multiplication

Use: a @ b…

Premium This card is part of the premium lesson. Unlock
Program
Example
Remember

- → Element-wise multiplicati……

Premium This card is part of the premium lesson. Unlock
Remember

@ → Matrix multiplication Ver……

Premium This card is part of the premium lesson. Unlock

Broadcasting

Definition

Broadcasting என்பது different but compatible shapes கொண்ட arrays-க்கு N……

Premium This card is part of the premium lesson. Unlock

Here scalar 5 behaves as if a……

Premium This card is part of the premium lesson. Unlock
Simple Explanation

Think: [10 20 30] + [ 5 5 5] = [15 25 35] NumPy ……

Premium This card is part of the premium lesson. Unlock
TRB Point

Broadcasting allows NumPy to perfor……

Premium This card is part of the premium lesson. Unlock

Data Type Conversion

Use: astype()…

Premium This card is part of the premium lesson. Unlock
Program
Example
Important

This truncates decimal parts ……

Premium This card is part of the premium lesson. Unlock

Explicit dtype

NumPy String and Mixed Values

NumPy usually tries to use a ……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

Likely output: [10. 20.5] float64 Integer may be ……

Premium This card is part of the premium lesson. Unlock
Important

NumPy arrays generally work best……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 1

Forgetting Import Wrong: a = np.array([1, 2, 3]) w……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 2

Writing numpy after aliasing to np If: import numpy a……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 3

List multiplication and NumPy m……

Premium This card is part of the premium lesson. Unlock
Output
Result

NumPy: np.array([1, 2]) * 2…

Premium This card is part of the premium lesson. Unlock
Output
Result
Common Mistake
Error 4

* means Matrix Multiplication……

Premium This card is part of the premium lesson. Unlock
Common Mistake

- → Element-wise…

Premium This card is part of the premium lesson. Unlock
Common Mistake

@ → Matrix multiplication…

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 5

Wrong reshape a = np.array([1, 2……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 6

Stop value in slicing a[1:4] Inde……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error 7

arange and linspace same என்று நினைப……

Premium This card is part of the premium lesson. Unlock
Memory Trick

NumPy Master Memory A D S S I M R A → Array D → Dimension S → Shape S → Size I → Indexing M → Mathemat……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 1

NumPy stands for: Numerical P……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 2

Common alias: import numpy as……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 3

Main NumPy array object: ndar……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 4

ndim gives number of dimensio……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 5

shape gives dimension sizes.…

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 6

size gives total number of el……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 7

dtype gives element data type.…

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 8

NumPy indexing starts at 0.…

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 9

NumPy supports negative index……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 10

Lists and NumPy arrays behave……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 11

NumPy supports element-wise o……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 12

np.arange() creates values ba……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 13

np.linspace() creates evenly ……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 14

np.zeros() creates zero-fille……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 15

np.ones() creates one-filled ……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 16

np.eye() creates identity mat……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 17

reshape() changes array shape……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 18

flatten() converts multidimen……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 19

.T gives transpose.…

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 20

- performs element-wise multi……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 21

@ performs matrix multiplicat……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 22

Boolean indexing can filter v……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 23

copy() creates an independent……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 24

view() usually shares underly……

Premium This card is part of the premium lesson. Unlock
TRB Point
TRB Point 25

Broadcasting allows operation……

Premium This card is part of the premium lesson. Unlock
Interview Point
Question 1

What is NumPy? Answer NumPy is a Python library for numerical and scie……

Premium This card is part of the premium lesson. Unlock
Interview Point
Question 2

What is ndarray? Answer ndarray stands for N-dimensional ar……

Premium This card is part of the premium lesson. Unlock
Interview Point
Question 3

Why is NumPy faster than normal Python lists for numerical operations? Answer NumPy arrays s……

Premium This card is part of the premium lesson. Unlock
Interview Point
Question 4

What is the difference between shape and size? Answer shape desc……

Premium This card is part of the premium lesson. Unlock
Interview Point
Question 5

What is the difference between arange() and linspace()? Answer arange() generally……

Premium This card is part of the premium lesson. Unlock
Interview Point
Question 6

What is broadcasting? Answer Broadcasting is NumPy's mechanism……

Premium This card is part of the premium lesson. Unlock
Interview Point
Question 7

What is the difference betwee……

Premium This card is part of the premium lesson. Unlock
Interview Point

- performs element-wise multi……

Premium This card is part of the premium lesson. Unlock
Interview Point
Question 8

What is the difference between copy and view? Answer A copy……

Premium This card is part of the premium lesson. Unlock
MCQ

NumPy stands for:…

Premium This card is part of the premium lesson. Unlock
MCQ

Which is the common NumPy ali……

Premium This card is part of the premium lesson. Unlock
MCQ

Which creates a NumPy array?…

Premium This card is part of the premium lesson. Unlock
MCQ

What is the output? import nu……

Premium This card is part of the premium lesson. Unlock
MCQ

Which property gives number o……

Premium This card is part of the premium lesson. Unlock
MCQ

What does shape return for a ……

Premium This card is part of the premium lesson. Unlock
MCQ

What does size return for a 2……

Premium This card is part of the premium lesson. Unlock
MCQ

What is the output? a = np.ar……

Premium This card is part of the premium lesson. Unlock
MCQ

Which function creates an arr……

Premium This card is part of the premium lesson. Unlock
MCQ

Which function creates evenly……

Premium This card is part of the premium lesson. Unlock
MCQ

What is the output? np.arange……

Premium This card is part of the premium lesson. Unlock
MCQ

What is the output? a = np.ar……

Premium This card is part of the premium lesson. Unlock
MCQ

Which operator performs eleme……

Premium This card is part of the premium lesson. Unlock
MCQ

Which operator performs matri……

Premium This card is part of the premium lesson. Unlock
MCQ

Which method changes the arra……

Premium This card is part of the premium lesson. Unlock
MCQ

Which converts a multidimensi……

Premium This card is part of the premium lesson. Unlock
MCQ

What does .T represent?…

Premium This card is part of the premium lesson. Unlock
MCQ 18

Which is used for Boolean filtering? A. ……

Premium This card is part of the premium lesson. Unlock
MCQ

Which property tells array el……

Premium This card is part of the premium lesson. Unlock
MCQ

NumPy is mainly useful for:…

Premium This card is part of the premium lesson. Unlock
Practice
Practice 1

Create this NumPy array: 10 20 30 40 50……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 2

Print the third element. prin……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 3

Print the last element using ……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 4

Create: 0 2 4 6 8 using NumPy……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 5

Create 5 evenly spaced values……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 6

Create a 2 × 3 zeros array. a……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 7

Create a 3 × 3 identity matri……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 8

Reshape: [1 2 3 4 5 6] into 2 × 3. ……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 9

Find: a = np.array([10, 20, 3……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 10

Filter values greater than 50: a = n……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 11

Find mean: a = np.array([10, ……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 12

Find maximum: print(np.max(a))…

Premium This card is part of the premium lesson. Unlock
Practice
Practice 13

Transpose: a = np.array([ [1,……

Premium This card is part of the premium lesson. Unlock
Practice
Practice 14

Explain difference between: a……

Premium This card is part of the premium lesson. Unlock
Practice

- → Element-wise multiplicati……

Premium This card is part of the premium lesson. Unlock
Practice

@ → Matrix multiplication…

Premium This card is part of the premium lesson. Unlock
Practice
Practice 15

Find all properties: a = np.array([ [10, 20, 30], [40, 50, 60] ]) Try: print(a.……

Premium This card is part of the premium lesson. Unlock
Summary

NumPy means Numerical Python. NumPy is used for numerical and scientific computing. Common import is import n……

Premium This card is part of the premium lesson. Unlock
Summary

- means element-wise multipli……

Premium This card is part of the premium lesson. Unlock
Summary

@ means matrix multiplication. Broadcasting allows compatible-shape operations. copy() creates independe……

Premium This card is part of the premium lesson. Unlock
Quick Revision

NumPy → Numerical Python Alias → np Main object → ndarray Create array → np.array() Dimensions → ndim Structu……

Premium This card is part of the premium lesson. Unlock
Text size
17px
Theme
Contents
Print / PDF
Program