[SciPy-user] how to filter outliers from an array

James Coughlan coughlan at ski.org
Mon Oct 30 14:48:57 CST 2006

How about this?

dx=rand(5,5) #substitute whatever matrices you're actually
dy=rand(5,5) #using here

import scipy.stats
#compute mean and std for dx and dy:

print wx | wy # logical or

Here wx and wy are arrays whose elements are set to True if they lie 
more than 1 std. from mean. So wx | xy will flag those elements for 
which either the x or y components are outliers.


Aaron Hoover wrote:

>Hi All,
>I'm doing feature matching between two images and as a result I get  
>back an array of dx, dy shift values in pixel space for potential  
>features that match between two images. I'd like to be able to throw  
>out [dx, dy] vectors for which either value deviates significantly  
>(more than one std deviation, perhaps) from the mean (I'm dealing  
>with 2D rigid body translations only. I could do this by looping over  
>the values and comparing them individually to the mean, but I'm  
>wondering if there's a more compact (single line?) way of doing this  
>perhaps using the scipy.stats package. Something along the lines of  
>the filter built-in for lists, but that handles the higher  
>dimensionality, would be nice.
>SciPy-user mailing list
>SciPy-user at scipy.org

James Coughlan, Ph.D., Associate Scientist                     

Smith-Kettlewell Eye Research Institute

Email: coughlan at ski.org
URL: http://www.ski.org/Rehab/Coughlan_lab/
Phone: 415-345-2146 
Fax: 415-345-8455

More information about the SciPy-user mailing list