Skip to content Skip to sidebar Skip to footer

Compare Two Different Size Matrices To Make One Large Matrix - Speed Improvements?

I have two matrices, that I need to use to create a larger matrix. Each matrix is simply a tab-delimited text file that is read. Each matrix has 48 cols with identical identifiers

Solution 1:

This is just a matrix multiplication. You want to multiply the first matrix by the transpose of the second. For efficient matrix operations, get NumPy.

If you read your two input matrices into NumPy arrays of dtype numpy.int8, then the computation is simply

m1.dot(m2.T)

It'll take a couple minutes, tops.


Solution 2:

I don't quite understand what this code does (the single letter variable names doesn't help).

My suggestion: Try to reduce how many operations you do in the innermost loops. For instance, do you need to recalculate pos in the inner level?

pos = header.index(k[0])

If it's possible to reorder the nested loops k, h and n, you might be able to cut down the costly list.index, which is a O(n) operation.


Post a Comment for "Compare Two Different Size Matrices To Make One Large Matrix - Speed Improvements?"