← Back to NumPy Course | Chapter 2: Creating Arrays | Lesson 4 of 7

np.linspace() से Sequence बनाना

np.linspace() आपको दो values के बीच evenly spaced points की एक exact संख्या देता है, end समेत।

In this page:

  1. np.linspace()
Syntax
python
np.linspace(start, stop, num)

np.linspace()

np.linspace(start, stop, num) num evenly spaced samples return करता है और default से stop include करता है। यह plotting axes और functions sample करने के लिए go-to tool है। Last point exclude करने के लिए endpoint=False set करें।

Note: points के बीच spacing भी पाने के लिए retstep=True इस्तेमाल करें।

उदाहरण: np.linspace()

python
import numpy as np

print(np.linspace(0, 1, 5))
print(np.linspace(0, 10, 4))
print(np.linspace(0, 1, 4, endpoint=False))

# Output:
# [0.   0.25 0.5  0.75 1.  ]
# [ 0.          3.33333333  6.66666667 10.        ]
# [0.   0.25 0.5  0.75]
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. third argument को एक step size से confuse करना
  2. यह भूल जाना कि endpoint included है
  3. linspace ज़्यादा safe होने पर floats के साथ arange इस्तेमाल करना
चैप्टर सारांश
  • linspace एक step नहीं बल्कि एक point count लेता है
  • Default से endpoint include करता है
  • Plotting ranges के लिए great
  • endpoint=False stop exclude करता है
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 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.