how to average only positive number in array numpy code example
Example: 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)