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 :: object get in djangi 
Python :: python event emitter 
Python :: python 3.9.7 
Python :: how to show type of a variable 
Python :: HTML default value fo radio button input type based on python variable 
Python :: how to seperate the script from html template when using jQuery in flask 
Python :: Flask error: werkzeug.routing.BuildError 
Python :: python class reflect method of member instance 
Python :: Python 3 (python 3.7.3) sample 
Python :: EDA describe missing and zero values 
Python :: containsDuplicate Set Solution 
Python :: random pick and remove index pandas 
Python :: ring get the type a given path (file or directory) 
Python :: negative max in python 
Python :: ring execute the program line by line 
Python :: how to get only the string of the input not the spaces arournd it in python 
Python :: circular ImportError: cannot import name 
Python :: set change order python 
Python :: python getpass save file 
Python :: websocket communitation to another pc python 
Python :: python apply file line 
Python :: pylatex multicolumn align 
Python :: add values to pandas plot 
Python :: text replace 
Python :: how to add trailing zeros in the number 
Python :: python send text 
Python :: any(iterable) 
Python :: Select a Column in pandas data Frame Using Brackets 
Python :: Crop Image as Circle with transparent background 
Python :: A Simple Class 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =