JYY
JYY

Reputation: 205

ojAlgo: slice or extract sub-matrix

In the java library ojAlgo, how can I slice a matrix or extract a sub-matrix from an existing one?

For example, matrix A = [[1,2,3],[4,5,6],[7,8,9]].

I am looking for a method which looks like slice(a,b,c,d) where a, b are the start and end indexes of the rows and c,d are the start and end indexes of the columns.

For example, if I call A.slice(1,3,1,3), it should return [[5,6],[8,9]].

I tried the slice method in SparseStore, but it does not work as I expected.

Upvotes: 1

Views: 430

Answers (1)

apete
apete

Reputation: 1320

The "slice" methods always return something 1D. You can slice out an index range, row, column, diagonal...

If you want a sub-view of a matrix you can do it this way:

matrix.logical().limits(3, 3).offsets(1, 1).get();

or with your example since the original matrix is 3x3, it's enough to do:

matrix.logical().offsets(1, 1).get();

Upvotes: 2

Related Questions