Answers for "how to average only positive number in array numpy"

0

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)
Posted by: Guest on April-07-2020

Code answers related to "how to average only positive number in array numpy"

Python Answers by Framework

Browse Popular Code Answers by Language