Method: Matrix.correspondence_matrix
- Defined in:
- lib/y_support/stdlib_ext/matrix/misc.rb
.correspondence_matrix(array1, array2) ⇒ Object
Given two arrays, creates correspondence matrix, with no. of cols equal to the 1st array, and no. of rows to the 2nd. This matrix can be used eg. for conversion between column vectors corresponding to the 1st and 2nd array:
Matrix.correspondence_matrix( array1, array2 ) * col_vector_1 #=> col_vector_2
39 40 41 42 43 |
# File 'lib/y_support/stdlib_ext/matrix/misc.rb', line 39 def self.correspondence_matrix( array1, array2 ) return Matrix.empty 0, array1.size if array2.empty? return Matrix.empty array2.size, 0 if array1.empty? self[ *array2.map { |e2| array1.map { |e1| e1 == e2 ? 1 : 0 } } ] # FIXME: Ordinary zero end |