+ 1
Help to find error
I want to add two arrays without using inbuilt function so please help https://code.sololearn.com/cQfXE5KX7mbi/?ref=app
2 Answers
+ 1
Keep in mind that numpy arrays add arrays in different ways than normal lists.
For example
Normal lists:
>>>[1,2,3] + [1,2,3]
[1,2,3, 1,2,3]
Np arrays
>>>[1,2,3] + [1,2,3]
[2,4,6]
So I suggest you to use normal lists instead of np arrays for this thing
+ 1
Your for loop goes
for i in arr1:
and then later, you call arr3[i]. As your arr1 array is [1,2,3,4,5], in your first iteration, i is 1, so arr3[i] is arr3[1] which is the second element in arr1, which is 2.
Then, on your second iteration, i = 2, so arr3[i] is 3. Then by the last iteration, i is 5 so arr3[5] is out of range. Try
for i in range(len(arr1)):
instead. That will remove the error.