Search code examples
pythonrmatrix-multiplication

Combine 2 2d matrices in one 2d matrix R


I have 2 two-dimensional matrices which I try to combine into 1. There are 3 common sets in each matrix, voyages barges and category's. I have an binary matrix which assigns barges to voyages, and I have a matrix which states the capacity of different categorys of cargo per barge. Now what I try to create is a table which gives the capacity per voyage based on which barge is assigned to it. I made some example data, my real data is tables and data frames in R;

enter image description here

table 1: capacity of category c for barge b

enter image description here

table 2: = 1 if barge b goes on voyage v

Now based on these 2 tables I want to get a table, which gives me the cap of each voyage, as follows;

enter image description here

table 3: output table

table 1 and 2 are both of type matrix in R

After I work the data I import it in python, so if someone knows how to do it there instead of in R, that would work fine as well.

Regards


Solution

  • You can try tcrossprod

    tcrossprod(tbl1,tbl2)