Created
March 21, 2013 22:12
-
-
Save dstu/5217272 to your computer and use it in GitHub Desktop.
Shuffling a list with a numpy.random.RandomState forgets the type of list elements if they're tuples.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pkg_resources | |
from collections import namedtuple | |
from numpy.random import RandomState | |
print pkg_resources.get_distribution("numpy").version | |
class Foo(namedtuple("Foo", "x")): | |
pass | |
items = [Foo(1), Foo(2), Foo(3)] | |
print type(items[0]) | |
rng = RandomState() | |
rng.shuffle(items) | |
print type(items[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running numpy 1.6 in Python 2.6.4 on x86-64 Linux, the first "print type(items[0])" prints 'main.Foo', while the second prints 'tuple'. After asking in #python on Freenode, it looks like the type of the list elements isn't forgotten in numpy 1.8.0.dev-75b8119 in Python 2.7.3.