Given a square matrix (i.e. an array of subarrays), find the sum of values from the first value of the first array, the second value of the second array, the third value of the third array, and so on...

## Examples

```
array = [[1, 2],
         [3, 4]]

diagonal sum: 1 + 4 = 5
```
                
```
array = [[5, 9, 1, 0],
         [8, 7, 2, 3],
         [1, 4, 1, 9],
         [2, 3, 8, 2]]

diagonal sum: 5 + 7 + 1 + 2 = 15
```

Source: codewars | Difficulty: EASY
Tags: Matrices

Fundamentals

Data structures

Starter code: def diagonal_sum(array):
	

Solutions:
def diagonal_sum(array):
	return sum((row[i] for (i, row) in enumerate(array)))


from numpy import trace as diagonal_sum


def diagonal_sum(array):
	return sum([array[a][a] for a in range(len(array))])


def diagonal_sum(array):
	return sum((row[idx] for (idx, row) in enumerate(array)))


def diagonal_sum(array):
	return sum([array[x][x] for x in range(0, len(array))])


def diagonal_sum(array):
	sum = 0
	for x in range(len(array)):
		for y in range(len(array[x])):
			if x == y:
				sum = sum + array[x][y]
	return sum


def diagonal_sum(a):
	return sum((l[i] for (i, l) in enumerate(a)))


def diagonal_sum(array):
	return sum((line[i] for (i, line) in enumerate(array)))


def diagonal_sum(array):
	sum = 0
	for n in range(len(array)):
		sum += array[n][n]
	return sum