0% found this document useful (0 votes)
9 views5 pages

Num Py Notes (Quick & Clear)

NumPy is a Python library for numerical computing that offers fast array operations, mathematical functions, and linear algebra support, making it essential for machine learning and data science. It allows for the creation of arrays of the same data type, provides various array types (1D, 2D, 3D), and includes features like indexing, slicing, and reshaping. Key advantages include lower memory usage, efficient mathematical operations, and the ability to handle large datasets.

Uploaded by

bariraa2007
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)
9 views5 pages

Num Py Notes (Quick & Clear)

NumPy is a Python library for numerical computing that offers fast array operations, mathematical functions, and linear algebra support, making it essential for machine learning and data science. It allows for the creation of arrays of the same data type, provides various array types (1D, 2D, 3D), and includes features like indexing, slicing, and reshaping. Key advantages include lower memory usage, efficient mathematical operations, and the ability to handle large datasets.

Uploaded by

bariraa2007
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

NumPy Notes (Quick & Clear)

1. What is NumPy?
NumPy (Numerical Python) is a Python library used for numerical computing. It provides support for
arrays, mathematical operations, and linear algebra, and is much faster than Python lists.

Why NumPy? - Fast and efficient - Less memory usage - Easy mathematical operations - Base of ML,
Data Science, Pandas, SciPy

2. Installing & Importing NumPy

pip install numpy

import numpy as np

3. NumPy Array
A NumPy array stores elements of the same data type.

Creating an Array

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


print(arr)

Difference: List vs Array

List NumPy Array

Slow Fast

Different data types Same data type

Less math support Powerful math operations

1
4. Types of Arrays

1D Array

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

2D Array

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

3D Array

[Link]([[[1,2],[3,4]], [[5,6],[7,8]]])

5. Array Attributes

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

- [Link] → number of dimensions - [Link] → rows & columns - [Link] → total


elements - [Link] → data type

6. Special Arrays

Zeros

[Link]((2,3))

Ones

[Link]((3,3))

Empty

[Link]((2,2))

2
Range

[Link](0, 10, 2)

Evenly Spaced

[Link](0, 10, 5)

7. Array Indexing & Slicing

arr = [Link]([10, 20, 30, 40])

- arr[0] → 10 - arr[1:3] → [20 30]

2D Indexing

arr[0,1]

8. Array Operations

Arithmetic Operations

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

a + b
a - b
a * b
a / b

Scalar Operations

a * 2
a + 5

3
9. Mathematical Functions

[Link](arr)
[Link](arr)
[Link](arr)
[Link](arr)
[Link](arr)
[Link](arr)

10. Reshaping Arrays

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

11. Copy vs View

a = [Link]() # deep copy


b = [Link]() # shallow copy

12. Stacking & Splitting

Stacking

[Link]((a,b))
[Link]((a,b))

Splitting

np.array_split(arr, 3)

13. Random Numbers

[Link](3,3)
[Link](1,10,5)

4
14. NumPy in Machine Learning
NumPy is used for: - Feature vectors - Matrix operations - Gradient calculations - Handling datasets

15. Important Exam Points ⭐


• NumPy arrays are faster than lists
• Uses contiguous memory
• Supports vectorization
• Used heavily in ML & Data Science

If you want: - Short exam notes - MCQs - Practice questions with answers - NumPy vs Pandas
comparison

Tell me 👍

You might also like