#Adding values of arrays in a shifted way

You have to write a method, that gets two parameter:

```markdown
1. An array of arrays with int-numbers
2. The shifting value
```

#The method should add the values of the arrays to one new array.

The arrays in the array will all have the same size and this size will always be greater than 0.
The shifting value is always a value from 0 up to the size of the arrays.
There are always arrays in the array, so you do not need to check for null or empty.

#1. Example:
```
[[1,2,3,4,5,6], [7,7,7,7,7,-7]], 0

1,2,3,4,5,6
7,7,7,7,7,-7

--> [8,9,10,11,12,-1]
```

#2. Example
```
[[1,2,3,4,5,6], [7,7,7,7,7,7]], 3

1,2,3,4,5,6
      7,7,7,7,7,7

--> [1,2,3,11,12,13,7,7,7]
```

#3. Example
```
[[1,2,3,4,5,6], [7,7,7,-7,7,7], [1,1,1,1,1,1]], 3


1,2,3,4,5,6
      7,7,7,-7,7,7
            1,1,1,1,1,1

--> [1,2,3,11,12,13,-6,8,8,1,1,1]
```

Have fun coding it and please don't forget to vote and rank this kata! :-)

I have created other katas. Have a look if you like coding and challenges.

Source: codewars | Difficulty: EASY
Tags: Data structures

Mathematics

Starter code: def sum_arrays(arrays, shift):
	

Solutions:
from itertools import zip_longest as zl

def sum_arrays(arrays, shift):
	shifted = [[0] * shift * i + arr for (i, arr) in enumerate(arrays)]
	return [sum(t) for t in zl(*shifted, fillvalue=0)]


from itertools import zip_longest

def sum_arrays(arrays, shift):
	shifted = [[0] * shift * i + array for (i, array) in enumerate(arrays)]
	return [sum(nums) for nums in zip_longest(*shifted, fillvalue=0)]


def sum_arrays(arrays, shift):
	shifted = [[0] * i * shift + a + [0] * (len(arrays) - i - 1) * shift for (i, a) in enumerate(arrays)]
	return list(map(sum, zip(*shifted)))


def sum_arrays(arr, shift):
	red = [[], arr][not shift]
	if shift > 0:
		la = len(arr)
		l0 = len(arr[0])
		lr = l0 + shift * (la - 1)
		ret = [0 * l0] * lr
		for (i, x) in zip(list(range(0, lr, shift)), list(range(la))):
			temp = ret[:]
			temp[i:l0 + i] = arr[x]
			red.append(temp)
	return [sum(a) for a in zip(*red)]


def sum_arrays(arrays, shift):
	dummy_arr = [0 for i in range(len(arrays[0]) + (len(arrays) - 1) * shift)]
	modified_arrays = []
	for i in range(len(arrays)):
		modified_arrays.append([0 for temp in range(i * shift)])
		modified_arrays[i] += arrays[i]
		if len(modified_arrays[i]) < len(dummy_arr):
			modified_arrays[i] += [0 for temp in range(len(dummy_arr) - len(modified_arrays[i]))]
	for i in range(len(dummy_arr)):
		for arr in modified_arrays:
			dummy_arr[i] += arr[i]
	return dummy_arr


import itertools

def sum_arrays(arrays, shift):
	return [sum(xs) for xs in itertools.zip_longest(*[[0] * (shift * i) + a for (i, a) in enumerate(arrays)], fillvalue=0)]


from itertools import zip_longest

def sum_arrays(arrays, shift):
	new_arr = []
	for (i, arr) in enumerate(arrays):
		new_arr.append([0] * shift * i + arr)
	return list(map(sum, zip_longest(*new_arr, fillvalue=0)))


def sum_arrays(arrays, shift):
	m = len(arrays)
	n = len(arrays[0])
	result = [0] * (n + shift * (m - 1))
	index = 0
	for a in arrays:
		for element in a:
			result[index] += element
			index += 1
		index += shift - n
	return result


def sum_arrays(arrays, shift):
	arrays_new = [arr[:] for arr in arrays]
	if shift == 0:
		return list(map(sum, zip(*arrays_new)))
	out = []
	(i, j) = (1, 1)
	while any((arr for arr in arrays_new)):
		out.append(sum((arr.pop(0) for arr in arrays_new[:i] if arr)))
		if j % shift == 0:
			i += 1
		j += 1
	return out


def sum_arrays(arrays, shift):
	l = []
	for i in range(len(arrays)):
		tmp = i * shift * [0] + arrays[i] + (len(arrays) - i - 1) * shift * [0]
		l.append(tmp)
	res = []
	for i in range(len(l[0])):
		tmp = sum([ii[i] for ii in l])
		res.append(tmp)
	return res