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

np.random.rand/randn का इस्तेमाल

rand 0 और 1 के बीच uniform numbers देता है और randn 0 पर centered bell-curve numbers देता है।

In this page:

  1. np.random.rand/randn
Syntax
python
np.random.rand(d0, d1)
np.random.randn(d0, d1)

np.random.rand/randn

np.random.rand(d0, d1, ...) [0, 1) में uniform values draw करता है। np.random.randn mean 0 और standard deviation 1 वाली standard normal distribution से draw करता है। दोनों dimensions को separate arguments की तरह लेते हैं, एक tuple नहीं।

Note: randn से mean m और standard deviation s पाने के लिए, m + s * randn(...) इस्तेमाल करें।

उदाहरण: np.random.rand/randn

python
import numpy as np

np.random.seed(1)
print(np.random.rand(2, 3).round(3))
print(np.random.randn(3).round(3))

# Output:
# [[0.417 0.72  0.   ]
#  [0.302 0.147 0.092]]
# [-0.528 -1.073  0.865]
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. rand या randn को एक tuple pass करना
  2. uniform और normal confuse करना
  3. यह भूल जाना कि values floats हैं
चैप्टर सारांश
  • rand 0 से 1 पर uniform है
  • randn standard normal है
  • Dimensions separate arguments हैं
  • mean + std * randn से scale करें
🔒

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.