0

Why is it concatenating rather than adding?

From array import * arr = array('i',(1,2,3)) arr1 = array('i',(4,5,6)) arr2 = arr + arr1 Print(arr2)

5th Jun 2020, 11:12 AM
Sagar Gupta
Sagar Gupta - avatar
4 Answers
+ 4
If you just want to (mathematically) add 2 python arrays, you can do: print([sum(x) for x in zip(arr, arr1)]) #[5, 7, 9] An other option would be to use map() with module operator, that has a function add() that can do the same. But why you are not using lists instead of python arrays?
5th Jun 2020, 12:04 PM
Lothar
Lothar - avatar
5th Jun 2020, 11:25 AM
Abhay
Abhay - avatar
5th Jun 2020, 11:25 AM
Sagar Gupta
Sagar Gupta - avatar