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

np.eye() से Identity Matrix

np.eye() एक identity matrix बनाता है: diagonal के साथ ones और बाकी हर जगह zeros।

In this page:

  1. np.eye()
Syntax
python
np.eye(n)
np.eye(rows, cols, k=offset)

np.eye()

Identity matrix number 1 का matrix equivalent है: इससे multiply करना कुछ नहीं बदलता। np.eye(n) एक n by n identity देता है; np.identity(n) similar है। k argument diagonal को ऊपर या नीचे shift करता है।

Note: np.diag आपकी अपनी diagonal values से एक matrix बना सकता है।

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

python
import numpy as np

print(np.eye(3))
print(np.eye(3, k=1, dtype=int))

# Output:
# [[1. 0. 0.]
#  [0. 1. 0.]
#  [0. 0. 1.]]
# [[0 1 0]
#  [0 0 1]
#  [0 0 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. एक integer size की बजाय एक shape tuple pass करना
  2. यह भूल जाना कि result default से float है
  3. eye को ones से confuse करना
चैप्टर सारांश
  • eye(n) एक identity matrix बनाता है
  • k diagonal shift करता है
  • Default dtype float है
  • identity से multiply करना एक matrix unchanged छोड़ता है
🔒

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.