-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumPy-broadcasting.py
More file actions
31 lines (26 loc) · 1.17 KB
/
Copy pathNumPy-broadcasting.py
File metadata and controls
31 lines (26 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#NumPy Broadcasting :-
#Broadcasting is a NumPy mechanism that allows arrays of different shapes and sizes to perform arithmetic operations together by automatically expanding the smaller array to match the larger array's dimensions without copying data
import numpy as np
a=np.array([1,2,3])
b=np.array([[1],[2],[3]])
print(a,b)
print(a+b)
#Output:- [1 2 3] [[1]
# [2]
# [3]]
# [[2 3 4]
# [3 4 5]
# [4 5 6]]
import numpy as np
a=np.array([1,2,3])
b=np.array([[1],[2],[3],[4]])
print(a,b)
print(a+b)
#Output:- [1 2 3] [[1]
# [2]
# [3]
# [4]]
# [[2 3 4]
# [3 4 5]
# [4 5 6]
# [5 6 7]]