What is the Julian equivalent of Python's `np.eye(5, 5, 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).

1 Like