New answers tagged

2

The most I've managed to improve the speed is about a factor of 2, but I thought I would share my attempt anyhow. First, let's just compute the identity matrix once, instead of once each iteration step: id = SparseArray[IdentityMatrix[2n]]; Second, since we are going to need all the powers of both A1 and A2, we can gain some speed by simply bumping the ...


6

SparseArray objects are somewhat special and some of the access operations can be slower with them. IdentityMatrix though does return a more compact object than just a list of lists -- it returns a packed array. Needs["Developer`"] Tally[ Table[PackedArrayQ[IdentityMatrix[n]], {n, Range[1, 1000, 10]}]] (* {{True, 100}}*) Also, it is really easy to ...


13

The fastest way to get the identity matrix as a sparse array is simply this: IdentityMatrix[10000, SparseArray]; // AbsoluteTiming Here are just some thoughts on why SparseArray is not the default for IdentityMatrix: You don't always want SparseArray output when defining matrices, and it's not always possible to decide automatically whether a SparseArray ...



Top 50 recent answers are included