← Back to NumPy Course | Chapter 9: Random Module | Lesson 5 of 6

np.random.shuffle() से Shuffle करना

shuffle एक array का order in place mix up करता है, cards का एक deck shuffle करने की तरह।

In this page:

  1. np.random.shuffle()
Syntax
python
np.random.shuffle(arr)    # in place

np.random.shuffle()

np.random.shuffle एक array के elements को इसकी पहली axis के along, in place rearrange करता है, और None return करता है। इसकी बजाय एक shuffled copy पाने के लिए np.random.permutation इस्तेमाल करें। 2-D arrays के लिए सिर्फ rows move होती हैं, rows के अंदर values नहीं।

Note: permutation(10) 0 से 9 का एक random ordering देता है, train/test splits के लिए ideal।

उदाहरण: np.random.shuffle()

python
import numpy as np

np.random.seed(7)
a = np.arange(8)
np.random.shuffle(a)
print(a)
print(np.random.permutation(5))

# Output:
# [2 5 0 6 3 1 4 7]
# [3 4 2 1 0]
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. shuffle के result को assign करना, जो None है
  2. यह उम्मीद करना कि columns भी shuffle होंगे
  3. जब आपको एक copy चाहिए था shuffling करना
चैप्टर सारांश
  • shuffle array को in place बदलता है
  • यह None return करता है
  • permutation एक copy return करता है
  • सिर्फ पहली axis shuffle होती है
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.