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

np.array() से Array बनाना

np.array() एक ordinary Python list को एक NumPy array में बदल देता है।

In this page:

  1. np.array()
Syntax
python
import numpy as np
arr = np.array([value1, value2, value3])
matrix = np.array([[a, b], [c, d]])

np.array()

np.array() एक list, tuple, या nested sequence से data को एक नए ndarray में copy करता है और dtype infer करता है। Input को nest करना dimensions add करता है। एक type force करने के लिए dtype argument इस्तेमाल करें।

Note:
  • np.array default से copy करता है।
  • जब input पहले से एक array हो copying avoid करने के लिए np.asarray इस्तेमाल करें।

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

python
import numpy as np

a = np.array([1, 2, 3])
b = np.array([[1, 2], [3, 4]])
c = np.array([1, 2, 3], dtype=float)

print(a)
print(b)
print(c)

# Output:
# [1 2 3]
# [[1 2]
#  [3 4]]
# [1. 2. 3.]
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. square brackets भूल जाना और separate arguments pass करना
  2. Ragged sequences pass करना
  3. एक copy की बजाय एक view की उम्मीद करना
चैप्टर सारांश
  • np.array sequences को ndarrays में convert करता है
  • Nested lists 2-D arrays बनाती हैं
  • dtype force किया जा सकता है
  • यह data की एक copy बनाता है
🔒

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.