PIXELBANKv8.2.1
Menu

Build Identity Matrix

Implement a function to generate an n×nn \times n identity matrix, a fundamental concept in linear algebra. The identity matrix is crucial in various mathematical operations, including matrix multiplication and transformation.

The identity matrix II is defined such that when it multiplies another matrix AA, the result is the original matrix AA. This property makes the identity matrix the multiplicative identity for matrices. The elements of the identity matrix can be defined using the Kronecker delta δij\delta_{ij}, where δij=1\delta_{ij} = 1 if i=ji = j and δij=0\delta_{ij} = 0 otherwise.

To construct the identity matrix, follow these steps:

  1. Initialize an n×nn \times n matrix with all elements set to 0.
  2. Iterate over each row and column, setting the element at position (i,j)(i, j) to 1 if i=ji = j, and 0 otherwise.
Iij=δijI_{ij} = \delta_{ij}

This technique is widely used in computer vision for image and signal processing.

Example:

Input:
identity_matrix(3)
Output:
[[1,0,0],[0,1,0],[0,0,1]]
Reasoning:

3×3 identity matrix

Constraints:

  • n is a positive integer, 1 ≤ n ≤ 100
Editor

Test Results

0/0
Run code to see test results.