0% found this document useful (0 votes)
2 views22 pages

Sem Python - NumPy Arrays Overview

The document provides an overview of the NumPy package in Python, focusing on arrays and vectorized computation, which includes creating arrays, important properties, special arrays, indexing, slicing, and various operations. It emphasizes the advantages of using NumPy, such as faster computation and support for multi-dimensional arrays, along with key exam questions and tips. Additionally, it briefly introduces the Pandas package for data analysis and manipulation.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views22 pages

Sem Python - NumPy Arrays Overview

The document provides an overview of the NumPy package in Python, focusing on arrays and vectorized computation, which includes creating arrays, important properties, special arrays, indexing, slicing, and various operations. It emphasizes the advantages of using NumPy, such as faster computation and support for multi-dimensional arrays, along with key exam questions and tips. Additionally, it briefly introduces the Pandas package for data analysis and manipulation.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

4/21/26, 6:08 AM sem python - NumPy Arrays Overview

i have a sem exam this is the 4 th unit 1st topicNumPy


package: Arrays and Vectorized Computation everygiive
ing thing on this topic for exam focused and explain
simple add outputs

Here’s a clear, exam-focused, simple explanation of


NumPy Package: Arrays & Vectorized Computation

🔷 1. What is NumPy?
NumPy (Numerical Python) is a Python library used for:
Fast calculations
Working with arrays (like lists but more powerful)
Main object: ndarray (N-dimensional array)
👉 Why use NumPy?
Faster than Python lists
Supports mathematical operations easily
Used in data science, ML, etc.

🔷 2. Creating NumPy Arrays


✔️ Import NumPy

import numpy as np

✔️ From Python List

a = [Link]([1, 2, 3])
print(a)

Output:
[Link] 1/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

[1 2 3]

✔️ 2D Array

b = [Link]([[1, 2], [3, 4]])


print(b)

Output:
[[1 2]
[3 4]]

🔷 3. Important Array Properties


a = [Link]([[1,2,3],[4,5,6]])

Property Meaning Example Output


[Link] Dimensions 2
[Link] Rows & columns (2,3)
[Link] Total elements 6
[Link] Data type int64

🔷 4. Special Arrays
✔️ Zeros

[Link]((2,3))

Output:
[Link] 2/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

[[0. 0. 0.]
[0. 0. 0.]]

✔️ Ones

[Link]((2,2))

Output:
[[1. 1.]
[1. 1.]]

✔️ Identity Matrix

[Link](3)

Output:
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]

✔️ Range

[Link](0,10,2)

Output:
[0 2 4 6 8]

🔷 5. Array Indexing & Slicing


a = [Link]([10,20,30,40])
print(a[1])

[Link] 3/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

Output:
20

Slicing

print(a[1:3])

Output:
[20 30]

2D Indexing

b = [Link]([[1,2],[3,4]])
print(b[1,1])

Output:
4

🔷 6. Array Operations
✔️ Element-wise Operations

a = [Link]([1,2,3])
b = [Link]([4,5,6])

print(a + b)

Output:
[5 7 9]

[Link] 4/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

print(a * b)
Python Run
Output:
[ 4 10 18]

🔷 7. Mathematical Functions
a = [Link]([1,4,9])

[Link](a)

Output:
[1. 2. 3.]

[Link](a)

Output:
14

[Link](a)

Output:
4.666...

🔷 8. Vectorized Computation (VERY IMPORTANT ⭐)


👉 Definition (Exam point):
Vectorization means performing operations on entire arrays without using loops.
[Link] 5/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

✔️ Example (Without loop)

a = [Link]([1,2,3])
print(a * 2)

Output:
[2 4 6]

✔️ Compare with Python loop

# Normal Python
result = []
for i in [1,2,3]:
[Link](i*2)
print(result)

👉 NumPy is faster because it avoids loops.

🔷 9. Broadcasting
👉 Allows operations between different size arrays

a = [Link]([1,2,3])
print(a + 5)

Output:
[6 7 8]

🔷 10. Reshaping Arrays


a = [Link]([1,2,3,4,5,6])
b = [Link](2,3)

[Link] 6/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

print(b)

Output:
[[1 2 3]
[4 5 6]]

🔷 11. Advantages of NumPy (Exam point)


Faster computation
Less memory usage
Easy mathematical operations
Supports multi-dimensional arrays

🔷 12. Important Exam Questions


👉 Prepare these:
1. What is NumPy? Explain ndarray.
2. Difference between list and NumPy array
3. Explain vectorization with example
4. What is broadcasting?
5. Explain array creation methods
6. Explain indexing & slicing
7. Write program using NumPy operations

🔷 13. Short Summary (Revise Before Exam)


NumPy = Numerical Python
ndarray = main object
Faster than lists
Vectorization = no loops
Broadcasting = operations on different sizes

If you want, I can also give:


✅ 2-mark answers
✅ Long answers (10 marks)
[Link] 7/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

✅ Important programs for exam


✅ Previous questions

The NumPy ndarray - Creating


ndarrays – Data Types for ndarrays – Arithmetic with
NumPy Arrays – Basic Indexing and
Slicing - Boolean Indexing - Transposing Arrays and
Swapping Axes.

Here’s your Unit 4 – Topic 1 (NumPy ndarray) explained in a simple, exam-focused


way with examples + outputs 👇

🔷 1. NumPy ndarray (Core Concept)


👉 Definition (write in exam):
ndarray is a multi-dimensional array object in NumPy that stores elements of the
same data type.
✔️ Example

import numpy as np
a = [Link]([1,2,3])
print(a)

Output:
[1 2 3]

👉 Features:
Homogeneous (same data type)
Fast operations
Supports multi-dimensions

🔷 2. Creating ndarrays
[Link] 8/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

✔️ From list

a = [Link]([1,2,3])

✔️ Using arange()

[Link](0,5)

Output:
[0 1 2 3 4]

✔️ Using zeros()

[Link]((2,2))

Output:
[[0. 0.]
[0. 0.]]

✔️ Using ones()

[Link]((2,2))

Output:
[[1. 1.]
[1. 1.]]

✔️ Using random()

[Link](2,2)

[Link] 9/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

Output (example):
[[0.45 0.67]
[0.12 0.89]]

🔷 3. Data Types for ndarrays


👉 Every array has a data type ( dtype )
✔️ Example

a = [Link]([1,2,3])
print([Link])

Output:
int64

✔️ Change data type

a = [Link]([1,2,3], dtype=float)
print(a)

Output:
[1. 2. 3.]

👉 Common types:
int
float
bool
complex

🔷 4. Arithmetic with NumPy Arrays ⭐


👉 Operations are element-wise
[Link] 10/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

✔️ Example

a = [Link]([1,2,3])
b = [Link]([4,5,6])

print(a + b)

Output:
[5 7 9]

print(a * b)

Output:
[ 4 10 18]

print(a ** 2)

Output:
[1 4 9]

👉 No loops needed → Vectorization

🔷 5. Basic Indexing and Slicing


✔️ Indexing

a = [Link]([10,20,30])
print(a[1])

Output:

[Link] 11/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

20

✔️ Slicing

print(a[0:2])

Output:
[10 20]

✔️ 2D Array

b = [Link]([[1,2],[3,4]])
print(b[1,0])

Output:
3

🔷 6. Boolean Indexing ⭐ (Very Important)


👉 Used to filter data
✔️ Example

a = [Link]([1,2,3,4])
print(a > 2)

Output:
[False False True True]

✔️ Use condition

[Link] 12/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

Python
print(a[a > 2])
Run
Output:
[3 4]

👉 Meaning:
Select elements greater than 2

🔷 7. Transposing Arrays
👉 Converts rows → columns
✔️ Example

a = [Link]([[1,2],[3,4]])
print(a.T)

Output:
[[1 3]
[2 4]]

🔷 8. Swapping Axes
👉 Used in multi-dimensional arrays
✔️ Example

a = [Link]([[[1,2],[3,4]]])
print([Link])

Output:
(1,2,2)

[Link] 13/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

print([Link](0,1))
Python Run
👉 Swaps axes positions

🔷 9. Quick Revision Table


Topic Key Idea
ndarray Multi-dimensional array
Creation array(), zeros(), ones()
dtype Data type
Arithmetic Element-wise
Indexing Access elements
Slicing Subset
Boolean Indexing Filtering
Transpose Rows ↔ Columns
swapaxes Change axis positions

🔷 10. Exam Tips ⭐


👉 Must remember:
Definition of ndarray
Boolean indexing example
Transpose syntax ( .T )
Arithmetic is element-wise
At least 1 program

If you want, I can give:


✅ Important 10-mark answers (ready to write)
✅ Short notes PDF style
✅ Practice questions + answers
[Link] 14/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

i have a sem exam this is the 4 th unit Pandas package:


Introduction to pandas Data Structures, Dataframe, Index
objects,
Reindexing, Dropping entries from axis, Indexing,
selection, and filtering, Arithmetic and
data alignment, Function application and mapping,
Sorting and ranking, Axis indexes with
duplicate values, Summarizing and Computing
Descriptive Statistics, Correlation and
Covariance, Unique Values, Value Counts, and
Membership. everygiive ing thing on this topic for exam
focused and explain simple add outputs

Here’s your Unit 4 – Pandas Package explained in a simple + exam-focused + with


outputs way 👇

🔷 1. Introduction to Pandas
👉 Definition (write in exam):
Pandas is a Python library used for data analysis and manipulation, especially with
tables (like Excel).
👉 Key features:
Handles structured data
Fast and easy operations
Built on NumPy

🔷 2. Pandas Data Structures ⭐


👉 Two main structures:
✔️ 1. Series (1D)

[Link] 15/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

import pandas as pd
s = [Link]([10,20,30])
print(s)

Output:
0 10
1 20
2 30
dtype: int64

✔️ 2. DataFrame (2D) ⭐ IMPORTANT


👉 Table with rows & columns

data = {'Name':['A','B'], 'Marks':[90,85]}


df = [Link](data)
print(df)

Output:
Name Marks
0 A 90
1 B 85

🔷 3. Index Objects
👉 Index = row labels

print([Link])

Output:
RangeIndex(start=0, stop=2, step=1)

👉 Columns also have index:

[Link] 16/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

print([Link])
Python Run

🔷 4. Reindexing
👉 Change row/column labels

df2 = [Link]([0,1,2])
print(df2)

Output:
Name Marks
0 A 90.0
1 B 85.0
2 NaN NaN

🔷 5. Dropping Entries from Axis


👉 Remove rows or columns
✔️ Drop row

[Link](0)

✔️ Drop column

[Link]('Marks', axis=1)

🔷 6. Indexing, Selection, Filtering ⭐


✔️ Column selection

[Link] 17/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

print(df['Name'])
Python Run
✔️ Row selection

print([Link][0])

✔️ Filtering

print(df[df['Marks'] > 85])

Output:
Name Marks
0 A 90

🔷 7. Arithmetic and Data Alignment


👉 Pandas aligns data by index automatically

df1 = [Link]({'A':[1,2]})
df2 = [Link]({'A':[3,4]})

print(df1 + df2)

Output:
A
0 4
1 6

🔷 8. Function Application & Mapping


✔️ apply()

[Link] 18/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

df['Marks'] = df['Marks'].apply(lambda x: x+5)


print(df)

Output:
Name Marks
0 A 95
1 B 90

🔷 9. Sorting and Ranking


✔️ Sorting

df.sort_values('Marks')

✔️ Ranking

df['Rank'] = df['Marks'].rank()
print(df)

🔷 10. Axis Indexes with Duplicate Values


👉 Pandas allows duplicate indexes

df = [Link]({'A':[1,2]}, index=['x','x'])
print(df)

👉 Access duplicates:

[Link]['x']

🔷 11. Summarizing & Descriptive Statistics ⭐


[Link] 19/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

print([Link]())

Output includes:
mean
min
max
std
count

🔷 12. Correlation and Covariance


[Link]()

Python Run
[Link]()

👉 Used to measure relationships between variables

🔷 13. Unique Values, Value Counts, Membership


✔️ Unique values
Python Run
print(df['Name'].unique())

Output:
['A' 'B']

✔️ Value counts
Python Run
print(df['Name'].value_counts())

[Link] 20/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

✔️ Membership
Python Run
print(df['Name'].isin(['A']))

Output:
0 True
1 False

🔷 14. Important Exam Questions ⭐


👉 Prepare these:
1. What is Pandas? Explain Series & DataFrame
2. Explain indexing and filtering
3. What is reindexing?
4. Explain apply() function
5. Explain sorting & ranking
6. What is correlation and covariance?
7. Explain descriptive statistics

🔷 15. Quick Revision (Last Minute)


Series = 1D
DataFrame = 2D
Index = labels
Filtering → condition
apply() → function
describe() → summary
corr() → relation
unique() / value_counts()

If you want, I can give:


✅ 2-mark answers (very short)
✅ 10-mark long answers ready to write
✅ Important programs for exam practice
✅ Previous question paper patterns
[Link] 21/22
4/21/26, 6:08 AM sem python - NumPy Arrays Overview

[Link] 22/22

You might also like