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

Numpy Easy Handmade Notes

Uploaded by

priyanshud773
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views12 pages

Numpy Easy Handmade Notes

Uploaded by

priyanshud773
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

NumPy Complete Notes (Beginner to Intermediate)

What is NumPy?

NumPy (Numerical Python) Python ki ek powerful library hai jo arrays aur


numerical calculations ke liye use hoti hai.

Import NumPy

import numpy as np

Why NumPy?

 Fast calculations

 Less memory usage

 Multi-dimensional arrays support

 Mathematical operations easy ho jati hain

 Data Science, AI, ML mein extensively use hota hai

1. Creating Arrays

[Link]()

Array create karne ke liye use hota hai.

1D Array Example

import numpy as np

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

print(arr)

2D Array Example

arr = [Link]([

[1, 2],

[3, 4]

])
print(arr)

[Link]()

Sab elements 0 create karta hai.

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

print(arr)

[Link]()

Sab elements 1 create karta hai.

arr = [Link]((2,2))

print(arr)

[Link]()

Same value se array fill karta hai.

arr = [Link]((2,2),5)

print(arr)

[Link]()

Range create karta hai.

arr = [Link](1,11)

print(arr)

[Link]()

Equal intervals create karta hai.

arr = [Link](0,10,5)

print(arr)
2. Array Indexing

Indexing kisi specific element ko access karne ke liye use hoti hai.

First Element Access

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

print(arr[0])

Last Element Access

print(arr[-1])

2D Indexing

arr = [Link]([

[1,2],

[3,4]

])

print(arr[1,1])

Important Points

 Positive Index → Left se start hota hai.

 Negative Index → Right se start hota hai.

 2D Array mein row,column format use hota hai.

3. Array Slicing

Array ka kuch part access karne ke liye use hoti hai.

Syntax

array[start:stop:step]

Example

arr = [Link]([10,20,30,40,50])
print(arr[1:4])

Every Second Element

print(arr[::2])

Important Points

 start → Kahan se start karna hai

 stop → Kahan tak jana hai

 step → Kitne gap se move karna hai

4. Data Types

Data Type array ke elements ka type batata hai.

Check Data Type

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

print([Link])

Change Data Type

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

new_arr = [Link](float)

print(new_arr)

Common Data Types

Typ
Meaning
e

int Integer

floa Decimal
t Number
Typ
Meaning
e

boo
True/False
l

str String

Important Methods

 [Link]

 [Link]()

5. Array Shape

Shape array ke rows aur columns ki information deta hai.

Example

arr = [Link]([

[1,2,3],

[4,5,6]

])

print([Link])

Output:

(2,3)

Meaning

 2 Rows

 3 Columns

Important Method

[Link]

6. Array Reshape
Reshape array ki shape change karta hai.

reshape() Example

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

new_arr = [Link](2,3)

print(new_arr)

flatten() Example

2D array ko 1D array mein convert karta hai.

arr = [Link]([

[1,2],

[3,4]

])

print([Link]())

Important Methods

 reshape()

 flatten()

7. Mathematical Operations

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

b = [Link]([4,5,6])

Addition

print(a+b)

Subtraction

print(a-b)

Multiplication
print(a*b)

Division

print(a/b)

Power

print(a**2)

Important Point

NumPy mein operations element-wise perform hote hain.

Important Mathematical Functions

Sum

[Link](arr)

Mean

[Link](arr)

Maximum

[Link](arr)

Minimum

[Link](arr)

Square Root

[Link](arr)

Most Used Functions

 [Link]()

 [Link]()

 [Link]()

 [Link]()

 [Link]()

8. Broadcasting
Broadcasting different shapes ke arrays ko automatically compatible bana
kar operation perform karne ki technique hai.

Example 1

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

print(arr + 5)

Example 2

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

print(arr * 10)

Important Point

Ek single value automatically array ke har element par apply ho jati hai.

9. Matrix Multiplication

Rows aur Columns ko multiply karke new matrix banayi jati hai.

Using @ Operator

A = [Link]([

[1,2],

[3,4]

])

B = [Link]([

[5,6],

[7,8]

])

result = A @ B
print(result)

Using [Link]()

result = [Link](A,B)

print(result)

Important Rule

A ke Columns = B ki Rows

Example:

(2×3) × (3×2)

Valid Multiplication

Important Methods

 A@B

 [Link]()

10. Dot Product

Corresponding elements ko multiply karke unka sum nikalta hai.

Example 1

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

b = [Link]([4,5,6])

print([Link](a,b))

Calculation

(1×4) + (2×5) + (3×6)

= 32

Example 2

marks = [Link]([80,90,70])
weights = [Link]([0.3,0.4,0.3])

print([Link](marks,weights))

Important Method

[Link]()

11. Linear Algebra Functions

Determinant

A = [Link]([

[1,2],

[3,4]

])

print([Link](A))

Why linalg?

linalg = Linear Algebra Module

Determinant NumPy ka normal function nahi hai, isliye:

[Link]()

use karte hain.

Inverse Matrix

[Link](A)

Work

Matrix ka inverse nikalta hai.

Transpose Matrix

A.T
Work

Rows ko columns aur columns ko rows mein convert karta hai.

Frequently Used NumPy Methods

Method Work

[Link]() Array Create

[Link]() All Zeros

[Link]() All Ones

[Link]() Same Value Fill

[Link](
Range Create
)

[Link]
Equal Intervals
()

[Link] Shape Check

[Link]
Shape Change
()

[Link](
Convert to 1D
)

[Link] Data Type Check

[Link]( Change Data


) Type

[Link]() Sum

[Link]() Average

[Link]() Maximum

[Link]() Minimum

[Link]() Square Root

[Link]() Dot Product


Method Work

[Link] Matrix
() Multiplication

Matrix
A@B
Multiplication

[Link].d
Determinant
et()

[Link]
Inverse Matrix
v()

A.T Transpose Matrix

Viva Revision (One Line)

 NumPy → Numerical Python Library.

 Array → Same type data ka collection.

 Indexing → Single element access.

 Slicing → Array ka part access.

 dtype → Data type batata hai.

 shape → Rows aur columns batata hai.

 reshape() → Shape change karta hai.

 flatten() → 2D ko 1D banata hai.

 Broadcasting → Different shapes par operation allow karta hai.

 Dot Product → Multiply + Sum.

 Matrix Multiplication → Row × Column multiplication.

 [Link]() → Determinant nikalta hai.

 [Link]() → Inverse matrix nikalta hai.

You might also like