Skip to content

Instantly share code, notes, and snippets.

@hkilis
Last active September 15, 2018 08:34
Show Gist options
  • Save hkilis/111e71d89c45f9000eeb10ff21a8f67d to your computer and use it in GitHub Desktop.
Save hkilis/111e71d89c45f9000eeb10ff21a8f67d to your computer and use it in GitHub Desktop.
include ExceptionForMatrix
def and_matrices(mx1, mx2)
Matrix.Raise ErrDimensionMismatch, "Matrix dimension mismatch" unless (mx1.row_count == mx2.row_count && mx1.column_count == mx2.column_count)
arr = Array.new(mx1.row_count){Array.new(mx1.column_count)}
mx1.each_with_index{ |elem, ix, iy| arr[ix][iy] = (elem && mx2.element(ix,iy)) }
Matrix.rows(arr)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment