I am a beginner in Python. I try to store the max value of two array in an another array. The length of array is known so I used c=[]*len(a)
a=[3,4,6,8]
b=[9,4,5,10]
c=[]*len(a)
for i in range(len(a)):
if (a[i]>b[i]):
c.append(a[i])
else:
c.append(b[i])
I got the following output, which is correct.
c=[9,4,6,10]
If I have arrays like
a=[[2,4],[6,8]]
b=[[1,7],[5,9]]
How should I proceed this to store the max value of each elements in an another array? Thank for your help in advance.
c=[]*len(a)yet so I'll explain it here. Using[] * len(a)will just give you[]for anyasince in Python, arrays/lists don't need to have a length declared before using them. So you can actually just doc = []and start appending things on toc. Hope I could help.