# \#matrices

**URL:** https://discourse.julialang.org/tag/matrices/405.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [\[ANN\]: PhaseTypeDistributions.jl, PhaseTypeDistributionsFitting.jl (and FixedSparsityMatrices.jl)](https://discourse.julialang.org/t/ann-phasetypedistributions-jl-phasetypedistributionsfitting-jl-and-fixedsparsitymatrices-jl/137631)

<div class="topic-metadata">

**Author:** [@yoninazarathy](https://discourse.julialang.org/u/yoninazarathy)\
**Replies:** 1\
**Last updated:** [June 25, 2026, 10:27am UTC](https://discourse.julialang.org/t/ann-phasetypedistributions-jl-phasetypedistributionsfitting-jl-and-fixedsparsitymatrices-jl/137631 "2026-06-25T10:27:55Z")

</div>

We’re happy to announce two new packages for phase-type (PH) distributions, plus a supporting third package for structured matrices (which may be useful in its own right). A phase-type distribution is the distribution o…

---

## [Matrix padding](https://discourse.julialang.org/t/matrix-padding/135250)

<div class="topic-metadata">

**Author:** [@rokke](https://discourse.julialang.org/u/rokke)\
**Replies:** 6\
**Last updated:** [January 26, 2026, 12:37pm UTC](https://discourse.julialang.org/t/matrix-padding/135250 "2026-01-26T12:37:59Z")

</div>

ok, I started opening things up to look at doing Pretty-printing small n-d arrays, but I came across a interesting choice which I wanted to make sure wasn’t a deliberate design decision. the left and right padding are co…

---

## [Is there a package for block-sparse matrix processing?](https://discourse.julialang.org/t/is-there-a-package-for-block-sparse-matrix-processing/133067)

<div class="topic-metadata">

**Author:** [@photor](https://discourse.julialang.org/u/photor)\
**Replies:** 5\
**Last updated:** [October 12, 2025, 7:46pm UTC](https://discourse.julialang.org/t/is-there-a-package-for-block-sparse-matrix-processing/133067 "2025-10-12T19:46:11Z")

</div>

As in the title, I mean every block is dense, but there are only a small percentage of non-vanishing blocks.

---

## [Matrix with zero columns multiplied by vector with zero elements yields vector](https://discourse.julialang.org/t/matrix-with-zero-columns-multiplied-by-vector-with-zero-elements-yields-vector/131518)

<div class="topic-metadata">

**Author:** [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Replies:** 11\
**Last updated:** [August 12, 2025, 12:29pm UTC](https://discourse.julialang.org/t/matrix-with-zero-columns-multiplied-by-vector-with-zero-elements-yields-vector/131518 "2025-08-12T12:29:06Z")

</div>

What is the reason behind this behavior? Type stability? I had expected this to either yield a two by zero matrix or throw an error. julia\> A = zeros( 2, 0 ) 2×0 Matrix{Float64} julia\> B = zeros( 0, ) Float64\[\] juli…

---

## [Slicing a matrix of matrices](https://discourse.julialang.org/t/slicing-a-matrix-of-matrices/131161)

<div class="topic-metadata">

**Author:** [@tduretz](https://discourse.julialang.org/u/tduretz)\
**Replies:** 5\
**Last updated:** [July 30, 2025, 7:29am UTC](https://discourse.julialang.org/t/slicing-a-matrix-of-matrices/131161 "2025-07-30T07:29:52Z")

</div>

I would like to better understand how to slice matrices of matrices. For example, I initialise a matrix of matrices this way: M = \[\[1 0; 0 2\] for i = 1:2, j=1:2\] If I slice it this way: M\[1,1\]\[:,:\] I obtain the result…

---

## [Package for dealing with symmetric matrices efficiently](https://discourse.julialang.org/t/package-for-dealing-with-symmetric-matrices-efficiently/130413)

<div class="topic-metadata">

**Author:** [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Replies:** 9\
**Last updated:** [July 4, 2025, 2:07am UTC](https://discourse.julialang.org/t/package-for-dealing-with-symmetric-matrices-efficiently/130413 "2025-07-04T02:07:16Z")

</div>

The Julia Symmetric Matrix type stores the full matrix. I’m looking for a package that offers a way to store and to index into a symmetric matrix directly but only stores one triangle, but that is performant, operates a…

---

## [\[ANN\] TypedMatrices.jl v1.2.0 - Package for Numerical Computation: Enhanced Matrix Search, Properties, Group Management, and Usability](https://discourse.julialang.org/t/ann-typedmatrices-jl-v1-2-0-package-for-numerical-computation-enhanced-matrix-search-properties-group-management-and-usability/128996)

<div class="topic-metadata">

**Author:** [@Andy\_Zhang](https://discourse.julialang.org/u/Andy_Zhang)\
**Replies:** 0\
**Last updated:** [May 14, 2025, 1:34pm UTC](https://discourse.julialang.org/t/ann-typedmatrices-jl-v1-2-0-package-for-numerical-computation-enhanced-matrix-search-properties-group-management-and-usability/128996 "2025-05-14T13:34:21Z")

</div>

Hi everyone, I’m happy to announce the release of TypedMatrices.jl v1.2.0! :tada: This version marks a feature-complete and stable milestone, ready for use in research, teaching, and numerical software development. Ov…

---

## [Possible speedup in matrix-diagonal products?](https://discourse.julialang.org/t/possible-speedup-in-matrix-diagonal-products/68474)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 6\
**Last updated:** [May 7, 2025, 9:11am UTC](https://discourse.julialang.org/t/possible-speedup-in-matrix-diagonal-products/68474 "2025-05-07T09:11:24Z")

</div>

Right multiplication by a Diagonal matrix effectively scales the columns of a matrix. Currently the default Matrix-Diagonal product appears to use copy\_similar: (\*)(A::AbstractMatrix, D::Diagonal) = rmul!(copy\_simil…

---

## [How to set all elements in a lower triangular matrix?](https://discourse.julialang.org/t/how-to-set-all-elements-in-a-lower-triangular-matrix/128603)

<div class="topic-metadata">

**Author:** [@Abhro](https://discourse.julialang.org/u/Abhro)\
**Replies:** 6\
**Last updated:** [May 2, 2025, 2:05pm UTC](https://discourse.julialang.org/t/how-to-set-all-elements-in-a-lower-triangular-matrix/128603 "2025-05-02T14:05:46Z")

</div>

I have a lower triangular matrix which gets reused. In one of the steps, I have all of the elements (below the diagonal) set to the same value. How do I make Julia understand that I’m not trying to set values above the d…

---

## [Concatenating scalar ranges into single row matrix](https://discourse.julialang.org/t/concatenating-scalar-ranges-into-single-row-matrix/128326)

<div class="topic-metadata">

**Author:** [@keynescoefen](https://discourse.julialang.org/u/keynescoefen)\
**Replies:** 4\
**Last updated:** [April 23, 2025, 8:29pm UTC](https://discourse.julialang.org/t/concatenating-scalar-ranges-into-single-row-matrix/128326 "2025-04-23T20:29:18Z")

</div>

Hello! I have a simple query about concatenating ranges into a row matrix. The desired output is \[0 1 2 3 4\] which I am trying to achieve with \[\[(1 - 1):0\]' \[1:5-1\]'\] However, the output I receive is 1×2 adjoint(::V…

---

## [Select specific elements from each column of a matrix in julia](https://discourse.julialang.org/t/select-specific-elements-from-each-column-of-a-matrix-in-julia/127138)

<div class="topic-metadata">

**Author:** [@alex180500](https://discourse.julialang.org/u/alex180500)\
**Replies:** 4\
**Last updated:** [March 19, 2025, 6:24pm UTC](https://discourse.julialang.org/t/select-specific-elements-from-each-column-of-a-matrix-in-julia/127138 "2025-03-19T18:24:16Z")

</div>

Let’s say I have this 16x1000 matrix: test\_mat = rand(16, 1000) And I have these indices: test\_indices = rand(1:16, 4, 1000) I want to extract from test\_mat a 4x1000 matrix where the indices of the row are represente…

---

## [Matrices and tensors with Symbolics.jl](https://discourse.julialang.org/t/matrices-and-tensors-with-symbolics-jl/119394)

<div class="topic-metadata">

**Author:** [@Damiano](https://discourse.julialang.org/u/Damiano)\
**Replies:** 6\
**Last updated:** [February 25, 2025, 1:29pm UTC](https://discourse.julialang.org/t/matrices-and-tensors-with-symbolics-jl/119394 "2025-02-25T13:29:04Z")

</div>

Hi all, three quick issues I encountered. Please correct me if I should have created different topics of if the Category is wrong. Best way to create a symmetric matrix This is the best I could come up with. A = Ar…

---

## [Most efficient way of adding elements within matrices in loops](https://discourse.julialang.org/t/most-efficient-way-of-adding-elements-within-matrices-in-loops/122789)

<div class="topic-metadata">

**Author:** [@BMI\_OR](https://discourse.julialang.org/u/BMI_OR)\
**Replies:** 4\
**Last updated:** [November 18, 2024, 11:31pm UTC](https://discourse.julialang.org/t/most-efficient-way-of-adding-elements-within-matrices-in-loops/122789 "2024-11-18T23:31:41Z")

</div>

I have a vector A and I need to update its values with the ones of matrix B. Each element of B needs to be added to some values in A. The mapping of indeces from matrix to vector is given by a matrix of vectors C. I have…

---

## [Wrong rank of this simple matrix](https://discourse.julialang.org/t/wrong-rank-of-this-simple-matrix/122477)

<div class="topic-metadata">

**Author:** [@singularity](https://discourse.julialang.org/u/singularity)\
**Replies:** 2\
**Last updated:** [November 11, 2024, 9:16am UTC](https://discourse.julialang.org/t/wrong-rank-of-this-simple-matrix/122477 "2024-11-11T09:16:11Z")

</div>

Hi. I am using Julia 1.10.4. I am using the LinearAlgebra package to compute rank, nullspace, et cetera for matrices. My code is unexpectedly throwing some errors and it turns out it seems to be calculating matrix rank i…

---

## [\[ANN\] TypedMatrices.jl – An Extensible Julia Matrix Collection Utilizing Type System](https://discourse.julialang.org/t/ann-typedmatrices-jl-an-extensible-julia-matrix-collection-utilizing-type-system/119668)

<div class="topic-metadata">

**Author:** [@Andy\_Zhang](https://discourse.julialang.org/u/Andy_Zhang)\
**Replies:** 0\
**Last updated:** [September 21, 2024, 9:31am UTC](https://discourse.julialang.org/t/ann-typedmatrices-jl-an-extensible-julia-matrix-collection-utilizing-type-system/119668 "2024-09-21T09:31:02Z")

</div>

Hi everyone, I’m excited to announce the release of TypedMatrices.jl, a new package designed to extend the Julia matrix ecosystem with a focus on performance and flexibility, leveraging Julia’s powerful type system. Ov…

---

## [How to concatenate matrices views without copying memory?](https://discourse.julialang.org/t/how-to-concatenate-matrices-views-without-copying-memory/118760)

<div class="topic-metadata">

**Author:** [@Blumenkranz](https://discourse.julialang.org/u/Blumenkranz)\
**Replies:** 3\
**Last updated:** [August 29, 2024, 1:08pm UTC](https://discourse.julialang.org/t/how-to-concatenate-matrices-views-without-copying-memory/118760 "2024-08-29T13:08:21Z")

</div>

Using vcat to catenate views leads to memory allocation which is contrary to the original intent of @views. CatViews.jl can address the issue to some extent, but it is only applicable to vectors. I wonder if there is a w…

---

## [Vector to Matrix. How to do it generally](https://discourse.julialang.org/t/vector-to-matrix-how-to-do-it-generally/118579)

<div class="topic-metadata">

**Author:** [@martin\_sanchez](https://discourse.julialang.org/u/martin_sanchez)\
**Replies:** 2\
**Last updated:** [August 25, 2024, 9:25am UTC](https://discourse.julialang.org/t/vector-to-matrix-how-to-do-it-generally/118579 "2024-08-25T09:25:56Z")

</div>

I have a DataFrame, and I am creating a function that receives it, extracts a few columns and convert those columns into a matrix. I was using Matrix{T}(df) and it worked, but when the slected columns turn to be 1, it sa…

---

## [Scaled diagonally dominant programming](https://discourse.julialang.org/t/scaled-diagonally-dominant-programming/116853)

<div class="topic-metadata">

**Author:** [@Khashayar-Neshat](https://discourse.julialang.org/u/Khashayar-Neshat)\
**Replies:** 2\
**Last updated:** [July 11, 2024, 8:47pm UTC](https://discourse.julialang.org/t/scaled-diagonally-dominant-programming/116853 "2024-07-11T20:47:52Z")

</div>

In polynomial optimization, one can check the certificate of nonnegativity with sums of squares (SOS) optimization which leads to semidefinite programming. Another more conservative approach is to use SDSOS optimization …

---

## [Solving linear system BC = X where B is a symmetric positive semi-definite matrix](https://discourse.julialang.org/t/solving-linear-system-bc-x-where-b-is-a-symmetric-positive-semi-definite-matrix/115280)

<div class="topic-metadata">

**Author:** [@Uranium238](https://discourse.julialang.org/u/Uranium238)\
**Replies:** 7\
**Last updated:** [June 6, 2024, 4:19pm UTC](https://discourse.julialang.org/t/solving-linear-system-bc-x-where-b-is-a-symmetric-positive-semi-definite-matrix/115280 "2024-06-06T16:19:18Z")

</div>

I am trying to solve for X in BC=X where B is a symmetric positive semi-definite matrix and X is simply a vector with 1 in all of it’s entries. As far as I understand, this can be solved using C=B\\X , but I was wondering…

---

## [Creating Single-Entry Matrix?](https://discourse.julialang.org/t/creating-single-entry-matrix/113932)

<div class="topic-metadata">

**Author:** [@ArcticOwl](https://discourse.julialang.org/u/ArcticOwl)\
**Replies:** 4\
**Last updated:** [May 7, 2024, 6:48am UTC](https://discourse.julialang.org/t/creating-single-entry-matrix/113932 "2024-05-07T06:48:35Z")

</div>

Hello everyone! I am new to Julia and I want to create single-entry matrices i.e., 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0…

---

## [How to construct a matrix of gradients depending on nodal locations in gridap](https://discourse.julialang.org/t/how-to-construct-a-matrix-of-gradients-depending-on-nodal-locations-in-gridap/113255)

<div class="topic-metadata">

**Author:** [@mary](https://discourse.julialang.org/u/mary)\
**Replies:** 0\
**Last updated:** [April 19, 2024, 9:52pm UTC](https://discourse.julialang.org/t/how-to-construct-a-matrix-of-gradients-depending-on-nodal-locations-in-gridap/113255 "2024-04-19T21:52:55Z")

</div>

Hi, I want to calculate the gradients of residuals(displacement) with respect to another vector. based on mathematical calculations, as residuals are a vector this gradient should be a matrix. This matrix should has val…

---

## [Nonconvex and Matrix Variables](https://discourse.julialang.org/t/nonconvex-and-matrix-variables/82056)

<div class="topic-metadata">

**Author:** [@chupin](https://discourse.julialang.org/u/chupin)\
**Replies:** 9\
**Last updated:** [March 11, 2024, 11:20pm UTC](https://discourse.julialang.org/t/nonconvex-and-matrix-variables/82056 "2024-03-11T23:20:01Z")

</div>

Is there any way to deal with matrix variables with Nonconvex lib ? I tried something like: using Nonconvex Nonconvex.@load Ipopt f(x) = sqrt(x\[2,2\]) g(x, a, b) = (a\*x\[1,2\] + b)^3 - x\[2,1\] model = Model(f) addvar!(mo…

---

## [Efficient ways to implement a (distributed) matrix-matrix product?](https://discourse.julialang.org/t/efficient-ways-to-implement-a-distributed-matrix-matrix-product/79466)

<div class="topic-metadata">

**Author:** [@Neo](https://discourse.julialang.org/u/Neo)\
**Replies:** 2\
**Last updated:** [February 27, 2024, 4:30pm UTC](https://discourse.julialang.org/t/efficient-ways-to-implement-a-distributed-matrix-matrix-product/79466 "2024-02-27T16:30:46Z")

</div>

There are a huge sparse matrix A and a tall-and-skinny matrix B (a set of multiple vectors). I want partition them into pieces for parallel distributed-memory matrix-matrix (matrix-vectors) multiplication. Is there any w…

---

## [Mul! generates machine noise](https://discourse.julialang.org/t/mul-generates-machine-noise/110477)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 21\
**Last updated:** [February 21, 2024, 8:24pm UTC](https://discourse.julialang.org/t/mul-generates-machine-noise/110477 "2024-02-21T20:24:06Z")

</div>

I have this simple matrix multiplication, but at the last step some machine noise is created and I don’t know why. This doesn’t happen in other programming languages. using LinearAlgebra function myfun1() a = 0.707…

---

## [KrylovKit, syntax issue](https://discourse.julialang.org/t/krylovkit-syntax-issue/110359)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 28\
**Last updated:** [February 21, 2024, 8:25am UTC](https://discourse.julialang.org/t/krylovkit-syntax-issue/110359 "2024-02-21T08:25:37Z")

</div>

So, I’m trying to use Lanczos diagnalization of a sparse marix of float64. Now I don’t want to specify the hint x0, so i just use rand(): Energy\[i\], psi\_ground, info = eigsolve(H\_super, rand(Float64, m\*2), 1, :SR, Lancz…

---

## [List of matrices](https://discourse.julialang.org/t/list-of-matrices/110456)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 6\
**Last updated:** [February 21, 2024, 7:33am UTC](https://discourse.julialang.org/t/list-of-matrices/110456 "2024-02-21T07:33:14Z")

</div>

Is there something better than this, to hold matrices? (not that i complain, just curious) C = Vector{AbstractMatrix{Float64}}(undef, 2) for i = 1:2 A = rand(Float64, i\*2, i\*2) display(A) C\[i\] = A end displa…

---

## [Mul! vs \* benchmarks](https://discourse.julialang.org/t/mul-vs-benchmarks/110448)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 2\
**Last updated:** [February 20, 2024, 4:41pm UTC](https://discourse.julialang.org/t/mul-vs-benchmarks/110448 "2024-02-20T16:41:23Z")

</div>

I have these 4 examles I’m benchmarking: using SparseArrays using LinearAlgebra using BenchmarkTools using Random function myfun1(m::Integer, n::Integer) Random.seed!(1) A = rand(Float64, n, n) B = sparse(r…

---

## [Krylovkit tolerance changes results drastically](https://discourse.julialang.org/t/krylovkit-tolerance-changes-results-drastically/110450)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 0\
**Last updated:** [February 20, 2024, 11:16am UTC](https://discourse.julialang.org/t/krylovkit-tolerance-changes-results-drastically/110450 "2024-02-20T11:16:17Z")

</div>

I’m writing a difficult to read code, just because I know the analytical result which is -0.274519. This value is meant to be compared with what is printed in the 4th column of this (a laptop is more than enough). When…

---

## [Constructing Q matrix from QR decomposition](https://discourse.julialang.org/t/constructing-q-matrix-from-qr-decomposition/110383)

<div class="topic-metadata">

**Author:** [@Endeavour](https://discourse.julialang.org/u/Endeavour)\
**Replies:** 3\
**Last updated:** [February 19, 2024, 10:20am UTC](https://discourse.julialang.org/t/constructing-q-matrix-from-qr-decomposition/110383 "2024-02-19T10:20:23Z")

</div>

Hi! I am working with some large complex float matrices ( that may go up to 16000x16000). I need to do a QR decomposition of a rectangular matrix. I require the Q matrix to be square. It seems like that extracting the Q…

---

## [MKL package wrong results](https://discourse.julialang.org/t/mkl-package-wrong-results/110405)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 6\
**Last updated:** [February 19, 2024, 10:26pm UTC](https://discourse.julialang.org/t/mkl-package-wrong-results/110405 "2024-02-19T22:26:22Z")

</div>

I have this program. I post it as it is. If I write: using MKL using MKLSparse It gives me (that’s an iteration of results with a matrix parameter on the first column): 02 | -0.37499999999999944 | 0.0 | -0.1874999999…

[Next page](https://discourse.julialang.org/tag/matrices/405.md?match_all_tags=true&page=1&tags%5B%5D=matrices)
