Python
Python
Exception Handling: Errors vs Exceptions. Built-in Exceptions (IndexError, KeyError, ImportError, etc.). The try, except, else, and
finally blocks.
2. GUI Interface (Tkinter): Introduction to tkinter Module. Root Window and Main Event Loop. Widgets: Label, Button, Entry,
Text, Checkbutton, Radiobutton, Listbox, Scrollbar. Layout Management: Pack, Grid, and Place geometry managers. Event
Handling (Binding functions to buttons/keys).
Python SQLite: The sqlite3 module. Connection Object & Cursor Object. SQL Operations: CREATE Table, INSERT data, SELECT
(fetching capabilities), UPDATE, and DELETE.
3. Data Analysis (NumPy & Pandas): NumPy (Numerical Python): Introduction to NumPy and Ndarray. Array Creation (from lists,
ranges, zeros, ones). Array Operations: Arithmetic, Slicing, Indexing, and Reshaping.
Pandas (Data Manipulation): Introduction to Series and DataFrames. Creating DataFrames from Dictionary, List of Tuples, CSV,
and Excel files. Data Inspection: head (), tail (), info (), describe ().
4. Data Visualization & Reporting: Introduction to Data Visualization: Importance of Visualization in Data Analysis. Matplotlib
Library: The pyplot interface. Plot Types: Line Chart, Bar Chart (Vertical/Horizontal), Histogram, Pie Chart. References: 1. Think
Python How to Think Like a Computer Scientist, Allen Downey et al., 2nd Edition, Green Tea Press. Freely available online @
File Handling:---
File handling in Python refers to the process of working with files stored on a computer system.
It allows a program to perform important operations such as creating, opening, reading, writing, and closing files.
Files help in permanent storage of data, which means the information remains saved even after the program ends.
Python provides a built-in function called open(). It is used to start working with a file. In Python, file handling is done using
built-in functions like open(), read(), write(), etc.
File handling is useful for storing user information, records, logs, reports, and large amounts of data.
File handling is commonly used in text editors, database systems, data analysis programs, and many real-world applications.
File Types
Files are mainly divided into two types based on how data is stored. These types help us decide how to read or write
information into the file.
1. Text Files
• These files store data in the form plain readable text. The data is arranged and stored line by line, and each line
usually ends with a newline character (\n). Text files can be easily opened and edited using text editors such as
Notepad, VS Code, or Notepad++.
• They usually have extensions such as .txt, .csv, .py, .html, .json, .xml
Examples:
Simple Meaning: A text file is like a normal notebook where you write simple words and sentences.
2. Binary Files
A binary file stores data in the form of binary digits (0s and 1s) instead of readable characters.
In binary files, the data is stored as bytes (rwa data), and it cannot be understood directly by humans without special software.
Binary files are mainly used to store complex data such as images, videos, audio, and executable programs.
Examples:
A binary file is like a coded storage system where the computer stores data using 0s and 1s, which humans cannot easily read.
[Link]. Text File Binary File
1 Stores data in plain text format. Stores data in binary (0s and 1s) format.
Occupies more space because data is stored as Occupies less space because data is compact in binary
characters. form.
4 Suitable for simple data like numbers, names, Suitable for complex data like images, audio, software,
messages. videos.
5 Slower processing because characters must be Faster processing because the computer directly works
converted into binary with binary data.
6 Example formats: .txt, .csv, .json Example formats: .bin, .exe, .jpg, .mp3, .xlsx
7 Editing can be done using any text editor (Notepad, Needs specific software to edit (Photoshop, Excel, etc.)
etc.)
Operations on Files
Python allows us to work with files using different operations such as Create, Open, Read, Write, and Close. All file operations
are done using the open() function.
[Link]()
1. Creating a File:-- A file can be created using write mode ("w") or append mode ("a"). If the file does not exist, Python
automatically creates a new file.
Example:
[Link]()
What happens?
• If [Link] does not exist → Python creates a new file and writes the text.
Common Modes:
Mode Meaning
Example:
3. Reading from a File:-- Reading means getting data from the file. Python provides three reading methods:
Example: This program reads all the text from [Link] and prints it.
content = [Link]()
print(content)
[Link]()
4. Writing to a File:-- Writing means adding new data to a file. We use the write mode ("w") or append mode ("a") to write
data.
Example:
[Link]()
Explanation:
This writes new text into the file.
(If the file already exists, "w" will overwrite it.) If the file does not exist, it is created.
5. Appending to a File:-- Append mode adds new data at the end of the file without deleting existing content. Mode used: a
(append mode).
Example:
[Link]()
6. Closing a File:-- After reading or writing, the file must be closed using: close().
Example:
[Link]()
1. File Name
A file name is the label/name given to a file so that it can be identified by the operating system and the user. Every file has a
name and an extension.
This is the actual name given to the file. Examples: notes, student_record, image1
The extension comes after a dot (.) and shows what type of file it is.
Examples:
2. File Path
A file path is the complete address or location of a file in the computer's directory (folder) structure. It tells the program exactly
where the file is stored so that it can be accessed. It shows how to reach the file from a particular location.
A. Relative Path
• It does NOT give the full location of the file. It does not start from the root directory.
Example:
This means the file [Link] is in the same folder as the Python program.
Another example:
• An absolute path gives the full address of the file starting from the root directory. It gives the exact
location of the file in the system. It starts from the root directory or drive.
• It is usually longer but very accurate and precise.
Format Operator
The format operator is represented by the % symbol in Python. It is used to insert values (like strings, integers, floats) into a
string in a formatted way.
• %s → string
• %d → integer
• %f → float
Multiple values can be inserted using a tuple: "%s is %d" % (name, age).
Decimal formatting can be controlled for floats using %.nf (e.g., %.2f → 2 decimal places).
• Exception Handling is a method used in programming to handle errors that occur during program execution.
• It allows a program to run continuously without crashing, even if an unexpected error happens.
• Using exception handling, we can write safe, error-free and reliable programs.
• It helps in identifying the error, controlling it, and giving meaningful messages to the user.
What is an Error?
• Errors usually occur before the code runs, during compilation or syntax checking.
• They must be fixed by the programmer.
Example of Error
print("Hello"
1. Syntax Errors
3. Logical Errors
1. Syntax Error
A syntax error occurs when the program does not follow the correct syntax rules of Python. These errors are detected before
the program runs. Ex:
A runtime error occurs while the program is running. These errors are called exceptions.
Example:
a = 10
b=0
print(a/b)
Output
3. Logical Error
A logical error occurs when the program runs without crashing but produces incorrect results. These errors are caused by
wrong logic in the program.
Example:
a = 10
b=5
print("Sum:", a - b)
Output
Sum: 5+
What is an Exception?
• Even if the syntax is correct, the program may face unexpected situations.
• Exceptions can be handled using try–except so the program does not stop.
a = 10 / 0
Output: ZeroDivisionError
Errors Exceptions
Errors occur due to serious issues in code or Exceptions are problems that occur during program execution
system. (runtime)..
Program stops immediately when an error occcurs Program continues running if exception is handled.
Indicates a problem in the code structure. Indicates a problem during runtime execution.
Built-in Exceptions in Python (Proper Explanation + Points)
Built-in exceptions are predefined errors in Python that occur when something goes wrong during the execution of a
program.
Python automatically shows these errors, and programmers can handle them using try and except blocks.
Example:
print(numbers[5]) # IndexError
KeyError
• Occurs when we try to access a key that is not present in a dictionary. It means the specified key is not found in the
dictionary. Usually happens due to wrong spelling or missing key.
Example:
print(student["marks"]) # KeyError
ImportError
• Occurs when Python cannot find a module that we are trying to import. Happens if module name is wrong or the
module is not installed. It indicates an issue with importing external libraries.
Example:
TypeError
• Occurs when an operation is applied to the wrong data type. Indicates incompatible types being used in an operation.
Example:
print("Hello" + 5) # TypeError
ValueError
• Occurs when the data type is correct but the value is invalid. Indicates the function received wrong or unexpected
value. Example: converting "abc" to an integer.
Example:
a = 10 / 0 # ZeroDivisionError
FileNotFoundError
Occurs when trying to open a file that does not exist. Happens due to wrong file name or wrong path. Indicates missing or
deleted file.
Example:
AttributeError
Occurs when you try to access an attribute/function that does not exist in an object.
• Happens due to spelling mistakes or wrong object. Python tells you the object has no such attribute.
Example:
x = "Hello"
[Link]("!") # AttributeError
Python’s built-in exceptions help identify runtime errors clearly. They make debugging easier by telling exactly what mistake
happened (wrong index, wrong key, wrong module, wrong type, etc.). Understanding these exceptions helps in writing error-
free and stable programs.
Try, Except, Else, Finally (Python Exception Handling)
Common Example Code (used for all explanations)
try:
result = 10 / num
except ZeroDivisionError:
else:
finally:
print("Program ended.")
• The try block contains the code that may cause an exception.
• If an error occurs inside try, the remaining try code stops immediately. Control automatically jumps to the
corresponding except block.
• int(input()) and 10 / num are inside try because they can cause errors.
• The except block runs if an error occurs in the try block. It handles the exception and prevents the program from
crashing.
• else block executes only when no error occurs in try block. Useful for writing code that must run after successful
execution. Keeps the program clean by separating “success logic” from “error logic”.
Using the Example: If user enters a valid non-zero number → else prints the result.
4. finally Block – Explanation
try:
except ZeroDivisionError:
except ValueError:
print("Invalid input")
else:
print("Result:", result)
finally:
1. try Block
The try block contains the code that may cause an error. Here, the program takes two numbers from the user and
performs division.
2. except ZeroDivisionError
This block handles the error when the second number is 0, since division by zero is not allowed.
3. except ValueError
This block runs when the user enters invalid input (such as letters instead of numbers).
4. else Block
The else block executes if no error occurs in the try block and prints the result of the division.
5. finally Block
The finally block always executes, whether an error occurs or not, and displays the message that the program has
finished execution.
Module : 2 GUI Interface in Python – Tkinter
A Graphical User Interface (GUI) allows users to interact with a program using windows, buttons, text boxes, and menus
instead of typing commands. In Python, GUI applications can be created using the Tkinter module.
Tkinter is the standard GUI library in Python that provides tools and widgets to build desktop applications easily.
• Tkinter is the standard GUI (Graphical User Interface) library for Python.
• It allows developers to create windows, buttons, text boxes, menus, and other GUI elements in a Python program.
• Tkinter acts as a bridge between Python and the Tk GUI toolkit. It allows Python programs to communicate with
the Tk library.
• Using Tkinter, developers can build desktop applications that users can interact with using a mouse
and keyboard instead of typing commands in the terminal.
Features of Tkinter
import tkinter as tk
import tkinter as tk
root = [Link]()
[Link]("Tkinter Example")
[Link]()
[Link]()
1. Root Window
Definition
• It is the first window created and serves as the parent for all other widgets (buttons, labels, frames, etc.).
• All other windows or widgets either attach to the root window or are created as child windows (Toplevel).
• Created using root = [Link]().
• It Can be customized: title, size, background color, and icon.
o title() → window title
• Closing the Root Window Ends the Program: When the user closes the root window, the entire application terminates.
Example
import tkinter as tk
[Link](pady=50)
Explanation
• The Main Event Loop is an infinite loop that keeps the window running and responsive.
• It waits for user events like button clicks, key presses, or mouse movements and responds accordingly.
• In Tkinter, it is called using: [Link]().
Example
import tkinter as tk
root = [Link]()
[Link]("400x200")
def on_click():
[Link](text="Button Clicked!")
[Link](pady=20)
[Link]()
Explanation
Definition Main window that holds widgets Loop that keeps GUI active and responsive
Purpose Container for all widgets Handles events and updates GUI
Customization Can set title, size, background, icon No customization; purely runs events
3. Widgets
Widgets are GUI elements that allow users to interact with the application. Tkinter provides a variety of widgets for building
interactive interfaces.
Widget Purpose
Label • A Label is used to display text or images in the GUI. It is non-editable by the
user.
Key Points
Key Points
Entry • An Entry widget is a single-line text input field. Users can enter or modify
text.
Key Points
Key Points
• Methods include get() for reading and insert() for writing text.
Key Points
Radiobutton • Radiobuttons allow the user to select only one option from a group.
Key Points
Key Points
Scrollbar • A Scrollbar allows the user to scroll through widgets like Text or Listbox when
content exceeds the visible area.
Key Points
• Can be vertical or horizontal.
• Linked to other widgets using command.
• Improves navigation for large content.
1. pack()
Key Points
Example: [Link](side="top")
2. grid()
• it is mainly used for forms and structured layouts. Each widget is placed in a specific cell.
Key Points
• Supports rowspan, columnspan, padding. Coordinates start from row=0, column=0 (top-left corner).
3. place()
Key Points
o Clicking a button
o Pressing a key
• When such an action occurs, it is called an event, and a specific function is executed to handle that event.
• Tkinter uses event-driven programming: the program waits for events and reacts.
• An event can be a button click, key press, mouse movement, or window action.
• You can bind an event to a widget using the .bind() method or Button’s command option.
1. Button Clicks
2. Key Presses
1. Button Events
Definition
Key Points
• Use the command option to trigger a function when the button is clicked.
• You can customize buttons with text, font, color, and size.
• For advanced control, you can use .bind() to detect single, double, or right-click.
2. Key Events
Definition
• A key event occurs when the user presses a key on the keyboard.
• You can bind a function to respond to specific keys or all key presses.
Key Points
1. Tkinter Architecture
Tkinter follows a layered architecture that connects Python programs with the Tk GUI toolkit.
1. Python Application
o This is the program written by the developer using Python.
o It contains instructions to create GUI components like labels, buttons, and text boxes.
2. Tkinter Module
o Tkinter acts as an interface between Python and the Tk toolkit.
o It converts Python commands into instructions that the Tk library understands.
3. Tk Toolkit
o Tk is a GUI toolkit written in C language.
o It provides the actual implementation of widgets such as buttons, menus, labels, etc.
4. Operating System
o The operating system finally displays the GUI window on the screen..
Thus , The Python program sends commands to Tkinter, Tkinter communicates with Tk toolkit, and the operating system
displays the GUI.
Simple Flow
Python Application
↓
Tkinter Module
↓
Tk Library (Tk Toolkit)
↓
Operating System GUI
import tkinter as tk
def login():
username = entry_user.get()
password = entry_pass.get()
print("Username:", username)
print("Password:", password)
root = [Link]()
[Link]("Login Form")
entry_user = [Link](root)
entry_pass = [Link](root, show="*")
entry_user.grid(row=0, column=1)
entry_pass.grid(row=1, column=1)
login_btn = [Link](root, text="Login", command=login)
login_btn.grid(row=2, column=1)
[Link]()
Explanation:
Widget Purpose
Example
import tkinter as tk
root = [Link]()
entry = [Link](root)
[Link]()
[Link]()
Explanation
Layout Style Arranges widgets vertically or Arranges widgets in rows and Places widgets at specific
horizontally columns coordinates
Usage Small/simple interfaces Forms and structured designs Custom GUI designs
1. Connection Object
2. Cursor Object
1. Connection Object
Definition
• The Connection object represents the connection between Python and the SQLite database.
• If the database does not exist, SQLite creates a new database file.
• Responsible for committing transactions (commit()) and closing the connection (close()).
Explanation
Definition
• The Cursor object is used to execute SQL queries and fetch data from the database.
SQLite Methods
1. connect()
1. Used to connect to an SQLite database. If the file does not exist, it creates a new database.
2. cursor()
1. Used to create a cursor object. The cursor helps to execute SQL commands.
3. execute()
1. Used to run SQL queries such as CREATE, INSERT, SELECT, UPDATE, DELETE. Takes SQL command as a string.
4. close()
1. Used to close the database connection. Helps to save memory and prevent data corruption.
3. Example: [Link]()
SQL Operations:
1. Connect to Database
• A database in SQLite is stored as a single .db file.
• The connect() method is used to create or open the database.
• If the database file name does not exist, SQLite creates it automatically.
• This is the first step before creating tables or inserting data.
• The connection object is used to perform all database operations.
Example: [Link]("file_name.db")
con = [Link]("[Link]")
2. Create Table
• A table stores data in rows and columns. Each table has columns with specific data types (like INTEGER, TEXT).
• If a table already exists, SQLite gives an error. To avoid this, use CREATE TABLE IF NOT EXISTS..
Example:
[Link]("CREATE TABLE IF NOT EXISTS Student(RollNo INTEGER, Name TEXT, Marks INTEGER)")
3. Insert Records
Example:
[Link]()
4. Select Records
• SELECT is used to retrieve and display data from the table..// Select is used to read or view data from the table.
• We use the SQL command SELECT to fetch specific columns or all columns.
• It helps us read and display stored information from the database.
• You can select all records or apply conditions using WHERE.
• fetchall() is used to get all rows
Example:
5. Update Records
Examples:
[Link]()
6. Delete Records
7. Drop Table
Example:
[Link]()
MODULE 3
NumPy (Numerical Python) is a Python library used for scientific and numerical. NumPy is widely used in data science,
machine learning, artificial intelligence, and scientific research because it performs calculations much faster than normal
Python lists.
It provides a special data structure called ndarray (N-dimensional array) that is faster and more efficient than Python lists.
NumPy arrays store data in continuous memory blocks, which improves performance.
NumPy is written in C and C++, which makes it much faster than native Python operations.
It supports multi-dimensional arrays (1D, 2D, 3D, etc.), useful for matrices and scientific data.
Importing NumPy
import numpy as np
Here:
• The ND Array is the main data structure of NumPy. It represents a collection of elements of the same
data type arranged in multiple dimensions.
• The term N-dimensional means the array can have any number of dimensions.
Types of ND Arrays
1.
• It automatically detects dimensions:
o 1D → simple list
o 2D → list of lists
o 3D → nested lists
Example:
import numpy as np
b = [Link]([[1, 2, 3],
2. Arrays of Zeros
• The zeros() function creates an array filled with zero values.
• It is useful when we need an empty structure to store values later.
• programmmer must specify the shape of the array (size, rows, columns).
• The default data type is float (0.0), but it can be changed.
Example:
Example: [Link](0, 1, 5)
NumPy provides powerful operations to work efficiently with arrays. These operations allow fast calculations, data access, and
shape manipulation, which are widely used in data analysis and scientific [Link] operations are fast because
NumPy uses optimized C code.
Arithmetic operations allow mathematical calculations on arrays such as addition, subtraction, multiplication, and division.
Code Example
import numpy as np
b = [Link]([2, 4, 6])
print(a + b) # Addition
print(a - b) # Subtraction
print(a * b) # Multiplication
print(a / b) # Division
Code Example
import numpy as np
print(arr[0])
print(arr[2])
print(arr[-1])
Explanation:→ arr[0] → First element. arr[2] → Third element. arr[-1] → Last element.
3. Slicing in NumPy Arrays
Array slicing means extracting a part (subset) of an array instead of using the full array.
Code Example
import numpy as np
print(arr[1:4])
print(arr[:3])
print(arr[0:5:2])
Explanation
Reshaping changes the shape (rows and columns) of an array without changing its data.
Code Example
import numpy as np
new_arr = [Link](2, 3)
print(new_arr)
Output
[[1 2 3]
[4 5 6]]
Introduction to Pandas
Pandas is a Python library used for data analysis and data manipulation.
It provides two main data structures: Series (1D) and DataFrame (2D).
It can read and write data from CSV, Excel, SQL, JSON, and many other formats.
It is built on top of NumPy, making it fast and efficient for large datasets.
Pandas is widely used in Data Science, Machine Learning, and Data Analytics.
It helps convert raw data into meaningful insights with simple commands.
1. Pandas Series –
A Series is a one-dimensional labeled array capable of holding any data type (integer, float, string, etc.). Each element in a
Series has an index that labels it. It is part of a DataFrame structure.
2. Indexing: Each element has an index (default is integers starting from 0, but you can set custom labels).
3. Holds any data type: Integers, floats, strings, Python objects, etc.
4. Immutable size: You can change values but not the size of the Series.
2. Pandas DataFrame –
A DataFrame in pandas is a two-dimensional labeled data structure with rows and columns. It is similar to a table in a
spreadsheet or a SQL table. DataFrames can be created from multiple sources like Excel files, CSV files, dictionaries, and
tuples.
import pandas as pd
data = {
"Name": ["John","Anna","Mike"],
"Age": [20,21,19]
df = [Link](data)
print(df)
Parameters:
Parameter Description
Note: Reading Excel files usually requires the openpyxl library internally.
1. Multiple Sheets – Can read data from different sheets in the same file.
4. Supports Complex Data – Useful for business reports and structured tables.
Syntax: df = pd.read_csv('[Link]')
Important Notes:
• It automatically reads column names from the first row. It loads data faster than Excel due to its simple text format.
2. Widely Supported – Almost all software and databases export data in CSV format.
5. Good for Data Exchange – Easy to share between systems and platforms.
Example
import pandas as pd
df = pd.read_csv('[Link]')
print(df)
• Each Keys must be unique and cannot be changed (immutable). Values can be any data type (numbers, strings, lists,
etc.).
• Dictionaries are unordered collections (do not follow indexing like lists).
• Data is accessed using keys, not index.
• Dictionary is mutable, meaning data can be added, removed, or changed.
• Created using curly braces {}.
Importance of Dictionary
• Ideal for structured data like student records, product details, etc.
Syntax:
df = [Link](data/dictionary)
Example:
import pandas as pd
data = {
df = [Link](data)
print(df)
Importance of Tuple
• Best for storing constant or fixed data that should not change.
Syntax
df = [Link](data, columns=[...])
Example
import pandas as pd
data = [
print(df)
Data inspection is the process of examining and understanding the structure and content of a dataset before performing
analysis.
In Pandas, several built-in functions help users quickly view the data, check its structure, and understand important statistical
information.
Pandas provides useful functions such as head(), tail(), info(), and describe() for data inspection.
Simple Diagram
Dataset (DataFrame)
│
┌─────┼─────┐
│ │ │
head() tail() info()
│
describe()
The head() function is used to display the first few rows of a DataFrame.
Syntax
[Link]()
Example
import pandas as pd
data = {
"Name": ["John","Anna","Mike","Sara","Tom"],
"Age": [20,21,19,22,23]
}
df = [Link](data)
print([Link]())
Output
Name Age
0 John 20
1 Anna 21
2 Mike 19
3 Sara 22
4 Tom 23
Important Points
Example:
[Link](3)
2. tail() Function
Syntax
[Link]()
Example
[Link]()
Output
Name Age
0 John 20
1 Anna 21
2 Mike 19
3 Sara 22
4 Tom 23
Important Points
Example:
[Link](2)
3. info() Function
• Column names
• Data types
• Non-null values
Syntax
[Link]()
Example
[Link]()
Example Output
<class '[Link]'>
RangeIndex: 5 entries, 0 to 4
Data columns (total 2 columns):
Name 5 non-null object
Age 5 non-null int64
Important Points
• count
• mean
• standard deviation
• minimum value
• maximum value
Syntax
[Link]()
Example
[Link]()
Example Output
Age
count 5.0
mean 21.0
std 1.58
min 19.0
max 23.0
Important Points
Data visualization helps transform complex data into simple visual representations, making analysis and decision-making
easier
1. Matplotlib
Matplotlib is a popular Python library used for creating charts, graphs, and visualizations from data.
It helps represent numerical data in graphical form for better understanding.
Key Points
2. It can create different types of graphs like line, bar, pie, and histogram.
Import Syntax
2. Pyplot
Pyplot is a module of Matplotlib that provides functions to create and control graphs easily.
Key Points
5. It is imported as plt.
Example
x = [1,2,3]
y = [10,20,30]
[Link](x,y)
[Link]()
To use any chart in Python, first import Pyplot: import [Link] as plt
LINE CHART
A Line Chart is a type of graph that displays data points connected by straight lines. A line chart shows the relationship
between two variables and is mainly used to display trends over time.
It is used to show changes, trends, or progressions over a continuous period.
Key Features
BAR CHART
A bar chart is used to compare values between different categories or group . A Bar Chart uses rectangular bars to represent
data.
A Vertical Bar Chart displays bars vertically. The categories are shown on the X-axis, and the values are shown on the Y-axis.
A Horizontal Bar Chart displays bars horizontally. The categories are shown on the Y-axis, and the values are shown on the X-
axis.
Key Points
A Histogram is a graphical representation that shows the frequency distribution of continuous data.
The data is divided into bins (intervals), and each bar shows how many values fall in each bin.
Key Features
PIE CHART
A Pie Chart is a circular graph divided into slices, where each slice represents a percentage of the whole dataset.
Key Points
Example Code
[Link](sizes, labels=labels)
[Link]()
Chart Type Definition Best Use
Line Chart Connects data points with lines to show trends Time-series data
1. Compares elements one-by-one between arrays. Returns a Boolean array (True/False). Useful for filtering and
conditional selection. Can compare array-to-array or array-to-scalar. Helps find values meeting certain conditions (ex:
>30).
1. Works on Boolean arrays created from comparisons. Used to combine multiple conditions. Returns a Boolean array.
More efficient than Python logical operators. Useful for filtering data with complex rules.
Perform operations that combine all values. Used for statistics like mean, sum, highest, lowest. Can apply on entire array
or specific axis. Very fast and optimized. Output is usually a single number (scalar).
Change the shape of an array without altering data. reshape() creates new dimensions. ravel() and flatten() convert array
to 1D. transpose() swaps rows and columns. Important for matrix operations and ML data.
Used to join and divide arrays. concatenate() joins arrays along an axis. vstack() stacks arrays vertically. hstack() stacks
arrays horizontally. split() divides arrays into equal parts.
Used for linear algebra applications. dot() performs matrix multiplication. Very fast due to optimized math libraries. Used in
ML, graphics, scientific calculations. Supports determinant, inverse, eigenvalues (via linalg).