Skip to content

Add axis option to numpy.random.shuffle #11583

Closed

Description

@CyanoKobalamyne

Currently, numpy.random.shuffle only supports shuffling along the first axis only. Many other Numpy functions support the axis keyword argument to specify the axis along which the respective operation should be applied, it would be great to have such an argument for this function as well.

Activity

  1. subhrm commented on Jul 20, 2018

    @subhrm
    Contributor

    I would suggest apply_along_axis . PFB an example :

    import numpy as np
    a = np.arange(40).reshape((5,8))       
    # shuffle along axis 1     
    np.apply_along_axis(np.random.shuffle,1,a) 
    # shuffle along axis 0
    np.random.shuffle(a)
    print(a)
    

    Example output:

    [[28 24 30 27 31 25 26 29]
     [39 36 37 33 38 35 34 32]
     [ 9 15 12  8 14 13 11 10]
     [22 17 23 19 20 16 18 21]
     [ 2  1  5  4  6  0  7  3]]
    
  2. WarrenWeckesser commented on Aug 13, 2019

    @WarrenWeckesser
    Member

    FYI: #5173

  3. wkschwartz commented on Oct 8, 2019

    @wkschwartz

    Can this be closed now because of #13829?

  4. CyanoKobalamyne commented on Oct 8, 2019

    @CyanoKobalamyne
    Author

    I believe so. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions