[Numpy-discussion] possible bug with character arrays and shuffle

Faheem Mitha faheem at email.unc.edu
Sun Sep 5 19:20:06 EDT 2004


Hi, 

Consider

********************************************************************
In [1]: import random

In [2]: import numarray.strings as numstr

In [3]: foo = numstr.array(['a', 'c', 'a', 'g', 'g', 'g', 'g',
   ...:                  'g','a','a','a','a'],shape=(12,1))

In [4]: foo
Out[4]:
CharArray([['a'],
           ['c'],
           ['a'],
           ['g'],
           ['g'],
           ['g'],
           ['g'],
           ['g'],
           ['a'],
           ['a'],
           ['a'],
           ['a']])

In [5]: for i in range(50):
   ...:     random.shuffle(foo)
   ...:

In [6]: foo
Out[6]:
CharArray([['a'],
           ['a'],
           ['a'],
           ['a'],
           ['a'],
           ['a'],
           ['a'],
           ['a'],
           ['a'],
           ['a'],
           ['a'],
           ['a']])
******************************************************************

Either I am doing something horribly wrong, or shuffle is badly
broken, since it is supposed to "shuffle list x in place". I haven't
checked shuffle carefully, but it seems to randomize for a bit Ok, and
then after a while, it suddenly starts returning all the same
characters.

It took me a while to track this one down. This is with Debian sarge
and package versions

ii  python2.3-numarray         1.0-2                      An array
processing package modelled after Python-Numeric
ii  python                     2.3.4-1                    An
interactive high-level object-oriented language (default version)

Please advise of a possible workaround. Or should I simply use a
different randomizing function, like sample?

Please cc me, I'm not subscribed. Thanks.

                                                       Faheem.






More information about the NumPy-Discussion mailing list