Replies: 2 comments
-
There is no ready made solution for that in mathjs. There are methods though to loop over your matrix, or read the value at a specific index, so you can write your own function to to this. |
Beta Was this translation helpful? Give feedback.
-
Since math.js already has the function* allSubmatrices(M) {
if (Array.isArray(M)) M = math.matrix(M)
const [ maxHeight, maxWidth ] = M.size()
for (let height = 1; height <= maxHeight; height++)
for (let width = 1; width <= maxWidth; width++)
for (let iStart = 0; iStart <= maxHeight - height; iStart++)
for (let jStart = 0; jStart <= maxWidth - width; jStart++) {
const iRange = math.range(iStart, iStart + height)
const jRange = math.range(jStart, jStart + width)
yield math.subset(M, math.index(iRange, jRange))
}
} However, using this to search for zero submatrices would be extremely ineffective even for quite small matrix sizes. If you want your code to perform, you'll need to think of something smarter – for example finding zero elements first and then checking if elements in a square around them are also zero. |
Beta Was this translation helpful? Give feedback.
-
I have a task. I need find all possible matrixes inside other matrix. Searchable matrix should consist from the same number. I need to define their indexes.
1, 0, 0, 1
1, 0, 0, 0
1, 1, 0, 1
Here I need to define that zero matrix has indexes 1, 0 and 2, 1.
Do we have methods in the lib to do that?
Beta Was this translation helpful? Give feedback.
All reactions