logo       

possible bug with character arrays and shuffle: msg#00019

python.numeric.general

Subject: possible bug with character arrays and shuffle

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.




-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise