最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Why is my Winsorization code telling me it has too many arguments? - Stack Overflow

programmeradmin1浏览0评论

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
  • What version of SciPy (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 that array is a NumPy masked array (np.ma.masked_array(array)). – Matt Haberland Commented Mar 18 at 18:13
  • Even going back as far as scipy 1.8.0, winsorize has always taken an array argument and a limits argument. The limits argument is supposed to be a tuple (your original call) rather than a list (your second call), but that's not the error you're getting. – Frank Yellin Commented Mar 18 at 20:08
  • Yeah, my only guess is that you have another function with the same name. These errors would not be produced by winsorize from a valid SciPy installation. – Matt Haberland Commented Mar 18 at 20:17
  • @MattHaberland You're correct; it was indeed me making a rookie mistake and not realising I have a separate function with the same name. Thanks for the help! – SRJCoding Commented Mar 19 at 9:12
Add a comment  | 

1 Answer 1

Reset to default 0

Issue 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.

发布评论

评论列表(0)

  1. 暂无评论