-
Notifications
You must be signed in to change notification settings - Fork 0
/
402136_ASSIGNMENT 5.py
93 lines (69 loc) · 4.03 KB
/
402136_ASSIGNMENT 5.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
## Broadcasting: Broadcasting means distribution.
##Broadcast program means the kind, content, volume and arrangement of matters to be broadcast.
##This division includes the activities of creating content or acquiring the right to distribute content.
# In[1]:
##1st case:
import numpy as np
a = np.array([[1, 2, 3, 5],[2, 5, 6, 2],[1,3,4,5], [2,3,4,5], [5,3,4,7]])
b = np.array([2])
c= a * b
print('a=', a)
print('b=', b)
print('c=', c)
# In[2]:
##2nd case:
import numpy as np
a = np.array([[1, 2, 3, 5],[2, 5, 6, 2],[1,3,4,5], [2,3,4,5], [5,3,4,7]])
b = np.array([2,3,4,5])
c= a * b
print('a=', a)
print('b=', b)
print('c=',c)
# In[3]:
##3rd case:
import numpy as np
a = np.array([[[1, 2, 3],[1, 2, 3],[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3]],[[1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3]],[[1, 2, 3],[1, 2, 3],[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3]], [[1, 2, 3],[1, 2, 3],[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3]], [[1, 2, 3],[1, 2, 3],[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3]]])
b = np.array([[[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2]],[[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2]],[[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2]],[[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2]],[[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2],[2]]])
c= a * b
print('a=', a)
print('b=', b)
print('c=',c)
# In[4]:
##4th case: Failed case due to trailing dimensions
import numpy as np
a = np.array([[[1, 2, 3],[1, 2, 3],[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3]],[[1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3]],[[1, 2, 3],[1, 2, 3],[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3]], [[1, 2, 3],[1, 2, 3],[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3]], [[1, 2, 3],[1, 2, 3],[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3]]])
b = np.array([[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5]])
c=a*b
print('a=', a)
print('b=', b)
print('c=',c)
# In[ ]:
##5th case: Failed case due to trailing dimensions
import numpy as np
a = np.array([[[1, 2, 3],[1, 2, 3],[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3]],[[1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3]],[[1, 2, 3],[1, 2, 3],[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3]], [[1, 2, 3],[1, 2, 3],[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3]], [[1, 2, 3],[1, 2, 3],[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],
[1, 2, 3], [1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3],[1, 2, 3]]])
b = np.array([[1],[2],[2]])
c=a*b
print('a=', a)
print('b=', b)
print('c=',c)