Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to average only positive number in array numpy

a = [[1, 2, 3, -1, -2, -3, -4, -1, 1, 2, 1, 2, 3, 2, 5],
     [1, 2, 3, -1, -2, -3, -4, -1, 1, 2, 1, 2, 3, 2, 5],
     [1, 2, 3, -1, -2, -3, -4, -1, 1, 2, 1, 2, 3, 2, 5]]

b = np.array(a)

def avg(a):
    return a[a > 0].mean()

np.apply_along_axis(avg, 1, b)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #average #positive #number #array #numpy
ADD COMMENT
Topic
Name
6+4 =