Reputation: 11
Why vectorized version of scipy.norm.cdf
is different from its scalar version?
I have to change to survival function (equals to 1-cdf).
Is it a bug or there are common usage of term cdf and sf?
My python is 3.9.2 and scipy version scipy 1.7.0.
norm.cdf(1.65, loc = 0, scale = 1)
norm([1.65,1.65],scale=1).cdf(np.zeros(2))
norm([1.65,1.65],scale=1).sf(np.zeros(2))
Output,
0.9505285319663519
array([0.04947147, 0.04947147])
array([0.95052853, 0.95052853])
Upvotes: 1
Views: 461
Reputation: 26090
The equivalence is norm.cdf(x, loc, scale)
and norm(loc, scale).cdf(x)
. This holds for both scalar and vectorized arguments:
In [2]: norm.cdf(1.65, loc=0, scale=1)
Out[2]: 0.9505285319663519
In [3]: norm(loc=0, scale=1).cdf(1.65)
Out[3]: 0.9505285319663519
In [4]: norm.cdf([1.65, 1.65], loc=0, scale=1)
Out[4]: array([0.95052853, 0.95052853])
In [5]: norm(loc=0, scale=1).cdf([1.65, 1.65])
Out[5]: array([0.95052853, 0.95052853])
To avoid confusion, I'd recommend to always use loc and scale as keyword arguments, even though the distributions accept them as positionals.
Upvotes: 4