What is the Julian equivalent of Pythonβs np.eye(5, 5, 1)
% python -q
>>> import numpy as np
>>> np.eye(5, 5, 1)
array([[0., 1., 0., 0., 0.],
[0., 0., 1., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 0., 0., 0., 1.],
[0., 0., 0., 0., 0.]])
Itβs I in the LinearAlgebra standard library:
In [1]: using LinearAlgebra
In [2]: I(5)
5Γ5 Diagonal{Bool, Vector{Bool}}:
1 β
β
β
β
β
1 β
β
β
β
β
1 β
β
β
β
β
1 β
β
β
β
β
1
Probably using diagm().
In your case:
diagm(1 => [1, 1, 1, 1]);
If you want efficient data structure you may use BandedMatrices.jl.
I am not aware of a data structure specialized for the case the diagonals have the values 0 or 1 (Namely no need for multiplication for Matrix Multiplication).
Note that the third index shifts the diagonal up creating an upper shift matrix instead of an identity.
Almost diagm(1 => [1, 1, 1, 1]) because of 5x5. Thanks!
Ah, apologies - an unusual use of eye then, given that the name as I understand it comes from Matlab and is a pun on the Identity matrix.