Extract lower triangle portion of a matrix

coolsv

I was wondering if there is a command or a package in Julia that permits us to extract directly the lower triangle portion of a matrix, excluding the diagonal. I can call R commands for that (like lowerTriangle of the gdata package), obviously, but I'd like to know if Julia has something similar. For example, imagine I have the matrix

1.0    0.751   0.734    
0.751   1.0    0.948    
0.734  0.948    1.0

I don't want to create a lower triangular matrix like

NA     NA      NA     
0.751   NA      NA    
0.734  0.948    NA

but extract the lower portion of the matrix as an array: 0.751 0.734 0.948

sundar - Reinstate Monica

If you're OK with creating a lower triangular matrix as an intermediate step, you can use logical indexing and tril! with an extra argument to get what you need.

julia> M = [1.0 0.751 0.734
0.751 1.0 0.948
0.734 0.948 1.0];
julia> v = M[tril!(trues(size(M)), -1)]
3-element Array{Float64, 1}:
0.751
0.734
0.948

The trues call returns an array of M's shape filled with boolean true values. tril! then prunes this down to just the part of the matrix that we want. The second argument to tril! tells it which superdiagonal to start from, which we use here to avoid the values in the leading diagonal.

We use the result of that for indexing into M, and that returns an array with the required values.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Extract respective upper and lower triangle's elements of matrix in R

Lower Triangle Matrix

Storing lower triangle of a matrix into an array

Copy upper triangle to lower triangle in a python matrix

matrix - mirror lower triangle to upper triangle

R reverse lower triangle matrix loop

Is there a way to parallelize a lower triangle matrix solver?

how to count the lower triangle elements in a matrix

How to reset the 'lower triangle' of a 3 dimentional matrix

Python generate a mask for the lower triangle of a matrix

Forcing upper triangle values to lower triangle values in matrix after melt

Extract one triangle of a correlation matrix with attributes

Extract upper or lower triangular part of a numpy matrix

Extract upper or lower triangular part of a numpy matrix

SymPy: Extract the lower triangular part of a matrix

R / creating a symmetric matrix out of the vector of the lower triangle elements

Pandas equivalent of max(lower triangle, upper triangle) on square matrix-like dataFrame

Restructure a matrix (which contains non-symmetrical values) into a lower triangle matrix format

Extract some portion of path

Extract portion of text with regex

EXTRACT PORTION OF STRING IN A CELL

Extract portion of nested tibbles?

How can I create a correlation matrix from 2 vectors of its upper and lower triangle in python?

Identifying the nth inserted element of matrix which fills by inserting alternating upper and lower triangle elements

How do I extract the lower/upper triangle of a non-square numpy array?

Return the exact portion string passing the same portion that is all lower case

Mask lower triangluar portion of pandas DataFrame

How to run portion of code in lower execution level

MATLAB - Editing a portion of a matrix with conditions