Calculating the sum of all columns of a 2D NumPy array Last Updated : 02 Sep, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Let us see how to calculate the sum of all the columns of a 2 dimensional NumPy array. Example : Input : [[1, 2, 3, 4, 5], [5, 6, 7, 8, 9], [2, 1, 5, 7, 8], [2, 9, 3, 1, 0]] Output : [10, 18, 18, 20, 22] Input : [[5, 4, 1, 7], [0, 9, 3, 5], [3, 2, 8, 6]] Output : [8, 15, 12, 18] Approach 1 : We will be using the sum() method. We will pass parameter axis = 0 to get the sum columns wise. python3 # importing numpy import numpy as np # initialize the 2-d array arr = np.array([[1, 2, 3, 4, 5], [5, 6, 7, 8, 9], [2, 1, 5, 7, 8], [2, 9, 3, 1, 0]]) # calculating column wise sum sum_2d = arr.sum(axis = 0) # displaying the sum print("Column wise sum is :\n", sum_2d) Output : Column wise sum is : [10 18 18 20 22] Approach 2 : We can also use the numpy.einsum() method, with parameter 'ij->j'. Python3 # importing numpy import numpy as np # initialize the 2-d array arr = np.array([[1, 2, 3, 4, 5], [5, 6, 7, 8, 9], [2, 1, 5, 7, 8], [2, 9, 3, 1, 0]]) # calculating column wise sum sum_2d = np.einsum('ij->j', arr) # displaying the sum print("Column wise sum is :\n", sum_2d) Output : Column wise sum is : [10 18 18 20 22] Comment More infoAdvertise with us Next Article Calculating the sum of all columns of a 2D NumPy array A aashishsaxena11222 Follow Improve Article Tags : Python Python-numpy Python numpy-Linear Algebra Practice Tags : python Similar Reads Calculate the sum of all columns in a 2D NumPy array Let us see how to calculate the sum of all the columns in a 2D NumPy array.Method 1 : Using a nested loop to access the array elements column-wise and then storing their sum in a variable and then printing it.Example 1:  Python3 # importing required libraries import numpy # explicit function to com 3 min read Calculate the sum of the diagonal elements of a NumPy array Sometimes we need to find the sum of the Upper right, Upper left, Lower right, or lower left diagonal elements. Numpy provides us the facility to compute the sum of different diagonals elements using numpy.trace() and numpy.diagonal() method. Method 1: Finding the sum of diagonal elements using nump 2 min read Calculate the mean across dimension in a 2D NumPy array We can find out the mean of each row and column of 2d array using numpy with the function np.mean(). Here we have to provide the axis for finding mean. Syntax: numpy.mean(arr, axis = None) For Row mean: axis=1 For Column mean: axis=0 Example: Python3 # Importing Library import numpy as np # creating 1 min read Find the sum and product of a NumPy array elements In this article, let's discuss how to find the sum and product of NumPy arrays. Sum of the NumPy array Sum of NumPy array elements can be achieved in the following ways Method #1:  Using numpy.sum() Syntax: numpy.sum(array_name, axis=None, dtype=None, out=None, keepdims=<no value>, initial= 5 min read How to calculate the element-wise absolute value of NumPy array? Let's see the program for finding the element-wise absolute value of NumPy array. For doing this task we are using numpy.absolute() function of NumPy library. This mathematical function helps to calculate the absolute value of each element in the array. Syntax: numpy.absolute(arr, out = None, ufunc 2 min read Like