HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
What is the difference between summation and addition?
What is the difference between summation and addition?
Addition is done between two arguments whereas summation happens over n elements.
Add the values in arr1 to the values in arr2:
import numpy as np
arr1 = np.array([1, 2, 3])
arr2 = np.array([1, 2,
3])
newarr = np.add(arr1, arr2)
print(newarr)
Returns: [2 4 6]
Sum the values in arr1 and the values in arr2:
import numpy as np
arr1 = np.array([1, 2, 3])
arr2 = np.array([1, 2,
3])
newarr = np.sum([arr1, arr2])
print(newarr)
Returns: 12
If you specify axis=1
, NumPy will sum the
numbers in each array.
Perform summation in the following array over 1st axis:
import numpy as np
arr1 = np.array([1, 2, 3])
arr2 = np.array([1, 2,
3])
newarr = np.sum([arr1, arr2], axis=1)
print(newarr)
Returns: [6 6]
Cummulative sum means partially adding the elements in array.
E.g. The partial sum of [1, 2, 3, 4] would be [1, 1+2, 1+2+3, 1+2+3+4] = [1, 3, 6, 10].
Perfom partial sum with the cumsum()
function.
Perform cummulative summation in the following array:
import numpy as np
arr = np.array([1, 2, 3])
newarr = np.cumsum(arr)
print(newarr)
Returns: [1 3 6]