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

Numpy Notes

The document provides comprehensive notes on NumPy, covering various topics such as creating arrays (1D, 2D, 3D), array properties (ndim, shape, size, dtype), and functions for array manipulation (zeros, ones, full, identity, etc.). It also includes examples of mathematical operations, slicing, sorting, and iteration over arrays, along with their respective outputs. The notes serve as a complete guide for understanding and utilizing NumPy effectively.

Uploaded by

ardrasreeraj135
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)
3 views12 pages

Numpy Notes

The document provides comprehensive notes on NumPy, covering various topics such as creating arrays (1D, 2D, 3D), array properties (ndim, shape, size, dtype), and functions for array manipulation (zeros, ones, full, identity, etc.). It also includes examples of mathematical operations, slicing, sorting, and iteration over arrays, along with their respective outputs. The notes serve as a complete guide for understanding and utilizing NumPy effectively.

Uploaded by

ardrasreeraj135
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 Complete Notes (1-45) with Code & Output

🧮 NumPy Notes
1. ndarray

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

Output:

[1 2 3]

2. 1D Array

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


print(arr)

Output:

[10 20 30]

3. 2D Array

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


print(arr)

Output:

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

4. 3D Array

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

Output:

[[[1 2]
[3 4]]

[[5 6]
[7 8]]]

5. ndim

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


print([Link])

Output:

6. shape

print([Link])

Output:

(2, 2)

7. size

print([Link])

Output:

2
8. dtype

print([Link])

Output:

int64

9. zeros

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

Output:

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

10. ones

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

Output:

[[1. 1. 1.]
[1. 1. 1.]]

11. full

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

Output:

3
[[7 7]
[7 7]]

12. identity

arr = [Link](3)
print(arr)

Output:

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

13. eye

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


print(arr)

Output:

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

14. complex

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


print(arr)

Output:

[1.+2.j 3.+4.j]

15. add

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

Output:

[4 6]

16. sub

print([Link](a,b))

Output:

[-2 -2]

17. mul

print([Link](a,b))

Output:

[3 8]

18. div

print([Link](a,b))

Output:

[0.33333333 0.5 ]

19. square

5
print([Link](a))

Output:

[1 4]

20. sqrt

arr = [Link]([1,4,9])
print([Link](arr))

Output:

[1. 2. 3.]

21. dot

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

Output:

[[19 22]
[43 50]]

22. reshape

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

Output:

[[0 1 2]
[3 4 5]]

6
23. flatten

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

Output:

[1 2 3 4]

24. arange

print([Link](1,10,2))

Output:

[1 3 5 7 9]

25. linspace

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

Output:

[ 1. 3.25 5.5 7.75 10. ]

26. 1D Slicing

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

Output:

[20 30 40]
[50 40 30 20 10]

7
27. 2D Slicing

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

Output:

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

28. sort

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

Output:

[1 2 3]

29. sum

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

Output:

10

30. axis=0

print([Link](arr, axis=0))

Output:

8
[4 6]

31. axis=1

print([Link](arr, axis=1))

Output:

[3 7]

32. max

print([Link](arr))

Output:

33. min

print([Link](arr))

Output:

34. argmax

print([Link](arr))

Output:

9
35. argmin

print([Link](arr))

Output:

36. argsort

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

Output:

[1 2 0]

37. floor

arr = [Link]([1.2, 2.7])


print([Link](arr))

Output:

[1. 2.]

38. ceil

print([Link](arr))

Output:

[2. 3.]

39. round

10
arr = [Link]([1.234,2.567])
print([Link](arr,1))

Output:

[1.2 2.6]

40. 1D Iteration

arr = [Link]([1,2,3])
for x in arr:
print(x)

Output:

1
2
3

41. 2D Iteration

arr = [Link]([[1,2],[3,4]])
for row in arr:
for val in row:
print(val)

Output:

1
2
3
4

42. split

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

11
Output:

[array([1, 2]), array([3, 4]), array([5, 6])]

43. where

arr = [Link]([1,2,3,4])
print([Link](arr>2))
print([Link](arr>2,'yes','no'))

Output:

(array([2, 3]),)
['no' 'no' 'yes' 'yes']

44. concatenate

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

Output:

[1 2 3 4]

45. filter

arr = [Link]([1,2,3,4,5])
filt = arr>2
new_arr = arr[filt]
print(new_arr)

Output:

[3 4 5]

12

You might also like