In the output i can view two outputs were printed
from numpy import *
a=array([1,2,3,4,5,6])
print(a)
b=array([7,8,9,1,2,3])
for x in (a,6):
print(a+b)
You don't need the for loop, just do it like this:
a=np.array([1,2,3,4,5,6])
b=np.array([7,8,9,1,2,3])
print(a+b)
#Output
[ 8 10 12 5 7 9]
[i+j for i,j in zip(a,b)]Also ensure to check the length of the two arrays, else you will run into ValueError.
from numpy import *
a=array([1,2,3,4,5])
print(a)
b=array([7,8,9,1,2])
print(b)
len_a = len(a)
len_b = len(b)
if len_a == len_b:
print(a+b)
else:
print("length of array_a = %d, len of array_b = %d, cannot add two arrays") % (len_a, len_b)
x = aand thenx = 6, thus callingprint(a+b)twice.aandbcoordinate-wise? If so, you can just doa+b. You don't need aforloop.