I have an array that looks like this:
[ 3.4 0. 10.6 ... -0.4 -0.4 0. ]
The array has around 13.5m values in it. I want to winsorize the top and bottom 5% to deal with outliers. This is the code I'm using:
from scipy.stats.mstats import winsorize
winsorized_array = winsorize(array, (0.05, 0.05))
However, this returns the following error message:
TypeError: winsorize() takes 1 positional argument but 2 were given
I've also tried the following variation:
from scipy.stats.mstats import winsorize
winsorized_array = winsorize(array, limits = [0.05, 0.05])
This returns the following error message, which doesn't make any sense to me, since as far as I can tell this is the same syntax found in the scipy documentation here:
TypeError: winsorize() got an unexpected keyword argument 'limits'
Does anyone know what I'm doing wrong please?
I have an array that looks like this:
[ 3.4 0. 10.6 ... -0.4 -0.4 0. ]
The array has around 13.5m values in it. I want to winsorize the top and bottom 5% to deal with outliers. This is the code I'm using:
from scipy.stats.mstats import winsorize
winsorized_array = winsorize(array, (0.05, 0.05))
However, this returns the following error message:
TypeError: winsorize() takes 1 positional argument but 2 were given
I've also tried the following variation:
from scipy.stats.mstats import winsorize
winsorized_array = winsorize(array, limits = [0.05, 0.05])
This returns the following error message, which doesn't make any sense to me, since as far as I can tell this is the same syntax found in the scipy documentation here:
TypeError: winsorize() got an unexpected keyword argument 'limits'
Does anyone know what I'm doing wrong please?
Share Improve this question asked Mar 18 at 17:00 SRJCodingSRJCoding 4755 silver badges18 bronze badges 4 |1 Answer
Reset to default 0Issue resolved by @MattHaberland - the code had a separate function with the name winsorize and only 1 positional argument, hence the error message. The name of this function has since been changed and the code works.
import scipy; scipy.__version__
) are you using? I can't reproduce that in 1.15.2. There's nothing wrong with your code. You might try ensuring thatarray
is a NumPy masked array (np.ma.masked_array(array)
). – Matt Haberland Commented Mar 18 at 18:13winsorize
from a valid SciPy installation. – Matt Haberland Commented Mar 18 at 20:17