eye(A)

eye(A)

Constructs an identity matrix of the same dimensions and type as A.

Examples

julia> eye(2)
2x2 Array{Float64,2}:
 1.0    0.0
 0.0    1.0
julia> eye(2,3)
2x3 Array{Float64,2}:
 1.0    0.0    0.0
 0.0    1.0    0.0
julia> foo = zeros((2,2));
julia> eye(foo)
2x2 Array{Float64,2}:
 1.0    0.0
 0.0    1.0

Create a square identity matrix:

julia> eye(3)
3×3 Array{Float64,2}:
 1.0  0.0  0.0
 0.0  1.0  0.0
 0.0  0.0  1.0

This example creates a 3x3 identity matrix where all the diagonal elements are 1 and all other elements are 0.

Create a larger identity matrix:

julia> eye(5)
5×5 Array{Float64,2}:
 1.0  0.0  0.0  0.0  0.0
 0.0  1.0  0.0  0.0  0.0
 0.0  0.0  1.0  0.0  0.0
 0.0  0.0  0.0  1.0  0.0
 0.0  0.0  0.0  0.0  1.0

In this example, a 5x5 identity matrix is created.

Handle edge cases:

julia> eye(0)
0×0 Array{Float64,2}

When n is 0, an empty matrix is returned.

julia> eye(1)
1×1 Array{Float64,2}:
 1.0

When n is 1, a 1x1 identity matrix is returned.

Common mistake example:

julia> eye(3.5)
ERROR: InexactError: Int64(3.5)

The eye function expects an integer value for n. Providing a non-integer value will result in an error. Make sure to pass a valid integer to eye.

See Also

Ac_ldiv_B, Ac_ldiv_Bc, Ac_mul_B, Ac_mul_Bc, Ac_rdiv_B, Ac_rdiv_Bc, At_ldiv_B, At_ldiv_Bt, At_mul_B, At_mul_Bt, At_rdiv_B, At_rdiv_Bt, A_ldiv_Bc, A_ldiv_Bt, A_mul_B!, A_mul_Bc, A_mul_Bt, A_rdiv_Bc, A_rdiv_Bt, Bidiagonal, cond, conv2, det, diag, diagind, diagm, diff, eig, eigvals, eigvecs, expm, eye, full, inv, isdiag, ishermitian, isposdef, isposdef!, issym, istril, istriu, logabsdet, logdet, lyap, norm, qrfact, rank, repmat, rot180, rotl90, rotr90, sortrows, sqrtm, SymTridiagonal, trace, Tridiagonal, tril, tril!, triu, triu!, writedlm,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: