

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Sum 2D array in Python using map() function
In this tutorial, we are going to find the sum of a 2D array using map function in Python.
The map function takes two arguments i.e., function and iterable. It passes every element of the iterable to the function and stores the result in map object. We can covert the map object into an iterable.
Let's see how to find the sum of the 2D array using the map function.
Initialize the 2D array using lists.
Pass the function sum and 2D array to the map function.
Find the sum of resultant map object and print it.
Example
See the code below.
# initializing the 2D array array = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] # passing the sum, array to function result = list(map(sum, array)) # see the result values # it contains sum of every sub array print(result)
Output
If you run the above code, you will get the following output.
[6, 15, 24]
Output
Now, find the sum of the result using the same sum function.
# finding the sum of result print(sum(result))
Output
If you add the above code snippet the above program and run it, you will get the following output.
45
Conclusion
If you have any doubts in the tutorial, mention them in the comment section.
- Related Questions & Answers
- Convert 2D array to object using map or reduce in JavaScript
- Prefix sum array in python using accumulate function
- Map function and Dictionary in Python to sum ASCII values
- Prefix sum array in python using the accumulate function
- Prefix Sum of Matrix (Or 2D Array) in C++
- Minimum sum submatrix in a given 2D array in C++
- Passing a 2D array to a C++ function
- sum() function in Python
- How to use my object like an array using map function in JavaScript?
- Map Sum Pairs in JavaScript
- Flatten a 2d numpy array into 1d array in Python
- How to store a 2d Array in another 2d Array in java?
- JavaScript: How to map array values without using "map" method?
- map count( ) function in C++
- Maximum sum rectangle in a 2D matrix