Search
 
SCRIPT & CODE EXAMPLE
 

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)
Comment

PREVIOUS NEXT
Code Example
Python :: np random list 
Python :: write a python program to find the second largest number in a list 
Python :: python code style 
Python :: Fastest way to Convert Integers to Strings in Pandas DataFrame 
Python :: python print without optional argument 
Python :: tkinter label border color 
Python :: python add hyphen to string 
Python :: how to change series datatype from object to float 
Python :: django request.data example 
Python :: iterating a list in python 
Python :: to get the number of unique values for each column 
Python :: accuracy for each class 
Python :: round float python 
Python :: python observer pattern 
Python :: python collections counter methods 
Python :: id3 algorithm code in python 
Python :: python iteration 
Python :: run python in c ++ 
Python :: python split range into n groups 
Python :: geckodriver seleniunm setup 
Python :: Send Fetch Request Django(Get Method) 
Python :: reshape SAS matrix 
Python :: python dataframe reihe anzeigen 
Python :: is str in pzthon 
Python :: python genetic algorithm library 
Python :: queue peek python 
Python :: keras load model with custom objects 
Python :: django delete instance 
Python :: add a constant to a list python 
Python :: destory image in pygame 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =