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

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

np.arange() एक start से एक stop तक equal steps में count करता है, बिल्कुल Python के range जैसा लेकिन एक array produce करते हुए।

In this page:

  1. np.arange()
Syntax
python
np.arange(start, stop, step)

np.arange()

np.arange(start, stop, step) half-open interval [start, stop) में evenly spaced values return करता है। range के उलट यह float steps accept करता है। Floats के साथ, rounding length को surprising बना सकता है, इसलिए वहाँ linspace prefer करें।

Note: एक argument के साथ, arange(5) 0 से शुरू होता है और 5 से पहले रुकता है।

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

python
import numpy as np

print(np.arange(5))
print(np.arange(2, 10, 2))
print(np.arange(0, 1, 0.25))

# Output:
# [0 1 2 3 4]
# [2 4 6 8]
# [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. यह उम्मीद करना कि stop value included होगी
  2. float steps इस्तेमाल करना और एक unexpected length पाना
  3. arange को linspace से confuse करना
चैप्टर सारांश
  • arange(start, stop, step) stop exclude करता है
  • Float steps के साथ काम करता है
  • एक ndarray return करता है
  • जब आपको exact count चाहिए linspace इस्तेमाल करें
🔒

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.