I cannot use Numpy or any other library function, since this is the question I need to do, I have to define my own path.
I am writing a function that takes two lists (2 dimensional) as arguments. The function should calculate the elemental product of both lists and store them in the third list and return this resulting list from the function. Example input lists:
LIST1:
[[2,3,5,6,7],[5,2,9,3,7]]
list2:
[[5,2,9,3,7],[1,3,5,2,2]]
The function displays the following list:
[[10, 6, 45, 18, 49], [5, 6, 45, 6, 14]]
This 2*5=10, 3*2=6, 5*9=45... etc.
, 2 () , , , , , () , 2-D ,
[[5,2,9,3,7],[1,3,5,2,2],[1,3,5,2,2]]
[[5,2,9,3,7],[1,3,5,2,2],[1,3,5,2,2],[5,2,9,3,7]]
.
def ElementwiseProduct(l,l2):
i=0
newlist=[]
newlist2=[]
newlist3=[]
while i==0:
a=0
while a<len(l[i]):
prod=l[i][a]*l2[i][a]
newlist.append(prod)
a+=1
i+=1
while i==1:
a=0
while a<len(l[i]):
prod=l[i][a]*l2[i][a]
newlist2.append(prod)
a+=1
i+=1
newlist3.append(newlist)
newlist3.append(newlist2)
print newlist3
list1=[[2,3,5,6,7],[5,2,9,3,7]]
list2=[[5,2,9,3,7],[1,3,5,2,2]]
ElementwiseProduct(list1,list2)