Ryan Neve wrote:
> Hello,
> 
> [...]
> This works, but is very slow for something that will be on the back end 
> of a web page.

Iterating in python is usually slow, so you should use numpy array 
methods if possible. I've made a faster version. It gives the same 
result for your test case, but you should test it further to see if it 
treats all cases properly.

Regards,
João Silva

------------------------------------------------

import numpy as np

sample_array = 
np.array(([np.nan,1,2,3,np.nan,5,6,7,8,np.nan,np.nan,11,12,np.nan,np.nan,np.nan]))

#Replace single nan with the neighbours average
sample_array[1:-1] = 
np.where(np.isnan(sample_array[1:-1]),(sample_array[:-2]+sample_array[2:])/2.0,sample_array[1:-1])

#Fix ... Number nan ...
sample_array[1:]= 
np.where(np.logical_and(np.logical_not(np.isnan(sample_array[:-1])),np.isnan(sample_array[1:])),sample_array[:-1],sample_array[1:])

#Fix ... nan Number ...
sample_array[:-1]= 
np.where(np.logical_and(np.logical_not(np.isnan(sample_array[1:])),np.isnan(sample_array[:-1])),sample_array[1:],sample_array[:-1])

print sample_array

------------------------------------------------


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to