I want to find a sum of a column in a matrix without using any package.
a = [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
If I want to extract a row I can write a[i] for ith row, but how to extract a particular column?
I want to find a sum of a column in a matrix without using any package.
a = [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
If I want to extract a row I can write a[i] for ith row, but how to extract a particular column?
So you can get the ith row with a[i] and you can get the nth value from row i with a[i][n] now if you want the column as a whole you will want something like this:
def getColumn(data,col):
    return [k[col] for k in data]
 
    
    You can access any element :
def sumColumn(m, column):
    sum = 0
    for row in range(len(m)):
        sum += m[row][column]
    return sum
column = 1
print("The sum for column number", column, "is", sumColumn(matrix, column))
