NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.sum.html
numpy.sum — NumPy v2.3 Manual
Elements to include in the sum. See reduce for details. ... An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, a scalar is returned.
GeeksforGeeks
geeksforgeeks.org › python › numpy-sum-in-python
numpy.sum() in Python - GeeksforGeeks
January 30, 2026 - Example 2: This example calculates the sum of a 2D array and shows how using different data types changes the output. ... import numpy as np arr = np.array([ [14, 17, 12, 33, 44], [15, 6, 27, 8, 19], [23, 2, 54, 1, 4] ]) print(np.sum(arr)) print(np.sum(arr, dtype=np.uint8)) print(np.sum(arr, dtype=np.float32))
numpy np sum
04:08
sum in numpy - YouTube
03:18
NumPy np.sum() Tutorial: Calculate Array Sums with Axis Parameters ...
03:31
Sum of NumPy Array in Python (3 Examples) | np.sum() Function of ...
numpy sum array
NumPy aggregate functions are easy!
NumPy
numpy.org › doc › stable › reference › generated › numpy.sum.html
numpy.sum — NumPy v2.5 Manual
Elements to include in the sum. See reduce for details. ... An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, a scalar is returned.
DataCamp
datacamp.com › doc › numpy › sum
NumPy sum()
NumPy's `sum()` function is a powerful tool for array computation and analysis, allowing users to efficiently compute the sum of array elements along a specified axis.
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.ndarray.sum.html
numpy.ndarray.sum — NumPy v2.2 Manual
Return the sum of the array elements over the given axis. Refer to numpy.sum for full documentation.
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.sum.html
numpy.sum — NumPy v2.1 Manual
Elements to include in the sum. See reduce for details. New in version 1.17.0. ... An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, a scalar is returned.
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ma.sum.html
numpy.ma.sum — NumPy v2.1 Manual
numpy.sum · equivalent function · Examples · >>> import numpy as np >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4) >>> x masked_array( data=[[1, --, 3], [--, 5, --], [7, --, 9]], mask=[[False, True, False], [ True, False, True], [False, True, False]], fill_value=999999) >>> x.sum() 25 >>> x.sum(axis=1) masked_array(data=[4, 5, 16], mask=[False, False, False], fill_value=999999) >>> x.sum(axis=0) masked_array(data=[8, 5, 12], mask=[False, False, False], fill_value=999999) >>> print(type(x.sum(axis=0, dtype=np.int64)[0])) <class 'numpy.int64'> On this page
NumPy
numpy.org › doc › stable › reference › generated › numpy.ndarray.sum.html
numpy.ndarray.sum — NumPy v2.5 Manual
ndarray.sum(axis=None, dtype=None, out=None, *, keepdims=<no value>, initial=<no value>, where=<no value>)#
Python Tutorial
pythontutorial.net › home › python numpy › numpy sum()
NumPy sum(): Calculate the Sum of Elements in an Array
August 16, 2022 - The numpy sum() function is an aggregate function that takes an array and returns the sum of all elements.
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.ndarray.sum.html
numpy.ndarray.sum — NumPy v2.0 Manual
Return the sum of the array elements over the given axis. Refer to numpy.sum for full documentation.
Codecademy
codecademy.com › docs › python:numpy › ndarray › .sum()
Python:NumPy | ndarray | .sum() | Codecademy
October 31, 2025 - The .sum() method returns the sum of array elements over a given axis.
Programiz
programiz.com › python-programming › numpy › methods › sum
NumPy sum() (With Examples)
NumPy median() The sum() function is used to calculate the sum of array elements along a specified axis or across all axes. import numpy as np array1 = np.array([1, 2, 3, 4, 5]) # use sum() to calculate sum of array1 elements result = np.sum(array1) print(result) # Output : 15 ·
SciPy
docs.scipy.org › doc › numpy-1.10.0 › reference › generated › numpy.sum.html
numpy.sum — NumPy v1.10 Manual
numpy.sum(a, axis=None, dtype=None, out=None, keepdims=False)[source]¶ · Sum of array elements over a given axis. See also · ndarray.sum · Equivalent method. cumsum · Cumulative sum of array elements. trapz · Integration of array values using the composite trapezoidal rule.
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ndarray.sum.html
numpy.ndarray.sum — NumPy v2.1 Manual
Return the sum of the array elements over the given axis. Refer to numpy.sum for full documentation.
Top answer 1 of 3
11
Use numpy.concatenate with sum:
print (np.concatenate(a).sum())
print (np.sum(np.concatenate(a)))
32
Performance: Depends of number of nested arrays and number of values in arrays, so best test in real data:
a = np.array([np.arange(5), np.arange(2), np.arange(7)] * 1000)
#print (a)
In [40]: %timeit np.concatenate(a).sum()
830 µs ± 22.5 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
In [41]: %timeit (np.sum(np.concatenate(a)))
835 µs ± 33.5 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
#original solution
In [42]: %timeit sum([np.sum(array) for array in a])
15.3 ms ± 85.9 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
Another solutions:
In [43]: %timeit sum(np.sum(array) for array in a)
17.4 ms ± 2.27 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)
In [44]: %timeit (sum(np.concatenate(a)))
2.28 ms ± 143 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
2 of 3
2
While your code is good, you can also use numpy.concatenate to concatenate your arrays and then calcuate the sum via numpy.sum, python builtin sum, or a sum function over the numpy array
import numpy as np
a = np.array([np.arange(5), np.arange(2), np.arange(7)])
print(np.sum(np.concatenate(a)))
#32
print(sum(np.concatenate(a)))
#32
print(np.concatenate(a).sum())
#32
NumPy
numpy.org › devdocs › reference › generated › numpy.ndarray.sum.html
numpy.ndarray.sum — NumPy v2.6.dev0 Manual
ndarray.sum(axis=None, dtype=None, out=None, *, keepdims=<no value>, initial=<no value>, where=<no value>)#