Для строк вам нужно только
sums_in_rows = list(map(sum, table1d))
print(sums_in_rows)
Для столбцов нужно больше
sums_in_columns = [0]*len(table1d[0]) # create list for all results
for row in table1d:
for c, value in enumerate(row):
sums_in_columns[c] += value
print(sums_in_columns)
Вы также можете преобразовать его в массив numpy, и тогда у вас будет
import numpy as np
arr = np.array(table1d)
print('rows:', arr.sum(axis=1))
print('cols:', arr.sum(axis=0))
print('total:', arr.sum())
from random import randint
dim1 = input("Insert first dimension: ")
dim1 = int(dim1)
dim2 = input("Insert second dimension: ")
dim2 = int(dim2)
table1d = []
#x = 0
for i in range(dim1):
table2d = []
for j in range(dim2):
table2d.append(randint(1, 170))
#table2d.append(x)
#x += 1
table1d.append(table2d)
print(table1d)
sums_in_rows = list(map(sum, table1d))
print(sums_in_rows)
sums_in_columns = [0]*len(table1d[0])
for row in table1d:
for c, value in enumerate(row):
sums_in_columns[c] += value
print(sums_in_columns)
import numpy as np
arr = np.array(table1d)
print(arr.sum(axis=1))
print(arr.sum(axis=0))
print(arr.sum())