[SciPy-user] scipy.stats.scoreatpercentile BUG ? (n, 1) shaped arrays versus (n, )
eleanor
e.howick at irl.cri.nz
Wed Mar 5 22:10:56 EST 2008
I've just tracked problems in my code down to this unexpected behaviour
>>> import scipy
>>> d = scipy.arange(1,100)
>>> scipy.stats.scoreatpercentile(d,50)
50
That's correct
Then shuffle the data
>>> scipy.random.shuffle(d)
>>> scipy.stats.scoreatpercentile(d,50)
50
Everything's still fine
Now try it with an array where d.shape = (99,1)
>>> d2 = d.reshape(-1,1)
>>> d2.shape
(99, 1)
>>> scipy.stats.scoreatpercentile(d2,50)
array([82])
What the!!!
>>> d2[49]
array([82])
The problem seems to be that the sort in scoreatpercentile
values = np.sort(a)
dosen't sort an (n, 1) array.
I've had many problems with scipy and numpy functions not dealing well with
(n,1) arrays when they expect (n,) or is it the other way round.
Which shape should I use with 1D arrays, to lessen my temper tantrums?
Eleanor
More information about the SciPy-User
mailing list