This is also the sum of the upper triangle of the outer vector product of the array with itself:
import numpy as np np.triu(np.outer([1,2,3,4],[1,2,3,4]),1).sum() 35
Step by step, it works as follows:
# outer product np.outer([1,2,3,4],[1,2,3,4]) array([[ 1, 2, 3, 4], [ 2, 4, 6, 8], [ 3, 6, 9, 12], [ 4, 8, 12, 16]]) # upper triangle np.triu(np.outer([1,2,3,4],[1,2,3,4]),1) array([[ 0, 2, 3, 4], [ 0, 0, 6, 8], [ 0, 0, 0, 12], [ 0, 0, 0, 0]]) # then the sum, which is the non-zero elements np.triu(np.outer([1,2,3,4],[1,2,3,4]),1).sum() 35