0

Here is my sample code:

ah = np.linspace(1, 20, 20)
print(ah)
>>> [  1.   2.   3.   4.   5.   6.   7.   8.   9.  10.  11.  12.  13.  14.  15.
      16.  17.  18.  19.  20.]

print(np.random.shuffle(ah))
>>> None

According to the docs, the input should be an array or a list. Why doesn't the sample code above work?

1 Answer 1

6

The reshuffle is inplace, the reshuffle function does not return anything:

Test Code:

ah = np.linspace(1, 20, 20)
print(ah)
print(np.random.shuffle(ah))
print(ah)

Results:

[  1.   2.   3.   4.   5.   6.   7.   8.   9.  10.  11.  12.  13.  14.  15.
  16.  17.  18.  19.  20.]

None

[  5.  15.  13.   8.   1.   2.  18.   7.  14.   4.  10.   6.  17.  11.  16.
  19.  12.   3.  20.   9.]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.