Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

np.random.shuffle corrupts astropy.table.Table #6318

Open
lpsinger opened this issue Jul 3, 2017 · 0 comments
Open

np.random.shuffle corrupts astropy.table.Table #6318

lpsinger opened this issue Jul 3, 2017 · 0 comments

Comments

@lpsinger
Copy link
Contributor

lpsinger commented Jul 3, 2017

Calling np.random.permutation() on an instance of Table correctly returns a randomly reordered version of the table, but calling np.random.shuffle() to randomly reorder the table in place eventually corrupts the data. I am using Astropy 1.3.3 and Numpy 1.13.0 with Python 2.7.13 from MacPorts on macOS Sierra (10.12.5). See example below.

>>> from astropy.table import Table
>>> import numpy as np
>>> np.random.seed(0)
>>> t = Table(rows=[[1, 2, 3], [4, 5, 6]])
>>> t
<Table length=2>
 col0  col1  col2
int64 int64 int64
----- ----- -----
    1     2     3
    4     5     6
>>> np.random.seed(0)
>>> np.random.permutation(t)
array([(4, 5, 6), (1, 2, 3)],
      dtype=[('col0', '<i8'), ('col1', '<i8'), ('col2', '<i8')])
>>> np.random.shuffle(t); t
<Table length=2>
 col0  col1  col2
int64 int64 int64
----- ----- -----
    1     2     3
    4     5     6
>>> np.random.shuffle(t); t
<Table length=2>
 col0  col1  col2
int64 int64 int64
----- ----- -----
    1     2     3
    4     5     6
>>> np.random.shuffle(t); t
<Table length=2>
 col0  col1  col2
int64 int64 int64
----- ----- -----
    1     2     3
    1     2     3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants