Calculating the sum of all columns of a 2D NumPy array Last Updated : 02 Sep, 2020 Comments Improve Suggest changes 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 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 How to get all 2D diagonals of a 3D NumPy array? Let's see the program for getting all 2D diagonals of a 3D NumPy array. So, for this we are using numpy.diagonal() function of NumPy library. This function return specified diagonals from an n-dimensional array. Syntax: numpy.diagonal(a, axis1, axis2)Parameters: a: represents array from which diag 3 min read Calculate average values of two given NumPy arrays Finding average of NumPy arrays is quite similar to finding average of given numbers. We just have to get the sum of corresponding array elements and then divide that sum with the total number of arrays. Let's see an example: Example 1: Calculate average values of two given NumPy 1d-arrays Python3 # 1 min read Averaging over every N elements of a Numpy Array In this article, we will learn how to find the average over every n element of a NumPy array. For doing our task, we will some inbuilt methods provided by NumPy module which are as follows: numpy.average() to calculate the average i.e the sum of all the numbers divided by the number of elementsnumpy 3 min read Find the memory size of a NumPy array In this post, we will see how to find the memory size of a NumPy array. So for finding the memory size of a NumPy array we are using following methods: Using size and itemsize attributes of NumPy array size: This attribute gives the number of elements present in the NumPy array. itemsize: This attri 2 min read Convert a 1D array to a 2D Numpy array Here we will learn how to convert 1D NumPy to 2D NumPy Using two methods. Numpy is a Python package that consists of multidimensional array objects and a collection of operations or routines to perform various operations on the array and processing of the array. Convert a 1D array to a 2D Numpy arr 3 min read Like