Most efficient way to access the off-diagonal entries of a matrix in Julia

  Kiến thức lập trình

Suppose I have a 200 x 200 zero matrix in Julia. What is the most efficient way to set the off-diagonal elements of the matrix using the elements of another matrix?

I have written this code:

function (A::Matrix{Complex64}, B::Matrix{Complex64})
  M = zeros(ComplexF64, 200, 200)
  OffDiags  = [i ≠ j for i ∈ 1:nbands, j ∈ 1:nbands]
  M[OffDiags] .= A[OffDiags] ./ B[OffDiags]
end

Is there is a more efficient way to do this?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT