Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

sum all values in a matrix python

#construct the matrix
matrix = [[1, 2], [4, 3]]

#iterate over the matrix summing all elements in the row
#give those row summations into a list
#sum the list to give you the answer
ans = sum([sum(row) for row in matrix])

print(ans)
10
Comment

find sum of all elements in a matrix by python

x = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
]

y = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
]


for i in range(3):
    for j in range(3):
        print(x[i][j] + y[i][j])
Comment

PREVIOUS NEXT
Code Example
Python :: create app in django 
Python :: install fasttext python 
Python :: what does int do in python 
Python :: reshape wide to long in pandas 
Python :: what is seaborn in python 
Python :: python exam questions pdf 
Python :: python cast list to float 
Python :: kivy change window size 
Python :: how to hide tensorflow warnings 
Python :: datetime object to string 
Python :: python lists as dataframe rows 
Python :: python delete from list 
Python :: keras lstm example 
Python :: python list remove at index 
Python :: swagger library for django 
Python :: tkinter simple notification 
Python :: how to execute bash commands in python script 
Python :: git help 
Python :: pandas check match string lowercase 
Python :: text widget get tkinter 
Python :: python aes encryption 
Python :: directory path with python argparse 
Python :: How to convert string date to datetime format in python 
Python :: discord.py mention user 
Python :: showing specific columns pandas 
Python :: how to add item to a list python 
Python :: requests save data to disk 
Python :: mid point formula 
Python :: change marker border color plotly 
Python :: how to add textbox in pygame window 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =