iterating through two numpy arrays applying a function in Python -




i have

import numpy np = np.array([np.nan,2,3]) b = np.array([1,np.nan,2]) 

i want apply function a,b, there fast way of doing this. (like in pandas, can apply)

specifically interesting in averaging , b, take average 1 of numbers when other number missing.

i.e. want return

 np.array([1,2,2.5]) 

for example above. however, know answer in more general setting (where want apply operation element-wise number of numpy arrays)

you can use numpy.nanmean, ignores nans:

np.nanmean([a, b], axis=0) # array([ 1. ,  2. ,  2.5]) 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

python - Read npy file directly from S3 StreamingBody -