Tag Info

Hot answers tagged

5

Using method that Guess who it is suggested I managed to get around 75% faster result. Unsample[x_] :=Riffle[temp = Riffle[x, x] // Transpose; temp, temp]//Transpose ans = Table[Map[Unsample[#] &, arr[[i]]], {i, 5000}]; // AbsoluteTiming Your suggested solution evaluates in 1 to 1.2 sec on my machine, while this one evaluates in 0.63 s. I suspect ...


4

To factor out numeric factors in any argument of Dot: (2 yy.(3 zz)).(4 zz) //. Dot[a___, d_?NumericQ b_, c___] :> d Dot[a, b, c] 24 yy.zz.zz Edit: If you want this to happen automatically, you can add the rule as a new definition for Dot: Unprotect[Dot]; Dot[a___, d_?NumericQ b_, c___] := d Dot[a, b, c] Protect[Dot]; Now the factoring happens ...


3

Just to separate this from a package-based answer. In Mathematica 10.2, you can now do this with the built-in function SmithDecomposition. So using the same matrix from my previous answer: mat = {{1, 2, 3}, {-2, 3, 1}, {3, 2, 1}}; MatrixForm /@ SmithDecomposition[mat] Where the second element is the Smith normal form.


3

Is the following sufficiently general? t[e_] := e /. Dot[Times[z1_ /;!ArrayQ[z1], Dot[z2__]], z3__] :> z1 Dot[z2, z3] Simplify[a, TransformationFunctions -> {Automatic, t}] (* yy.zz.zz *)


2

The problem is with the behaviour of Set. Consider the following example: a = {1,2,3,4,5}; a[[2;;]] = {1,2,3,4} a[[3;;]] = {1,2,3,4} a[[4;;]] = {1,2,3,4} a[[5;;]] = {1,2,3,4} Notice that in the [[2;;]] part, Mathematica decides you want to replace elements 2, 3, 4 and 5 of a with the corresponding elements 1, 2, 3, 4 rather than all with the list ...


1

You say that you have several lists of tuples so I assume you wish to map your Select to them all like: Select[#, #[[1]] > 2 &] & /@ {l1, l2, l3} If you find the nesting of the slots, #, confusing then you could use the explicit form of Function, e.g. Function[{lst}, Select[lst, Function[{elem}, elem[[1]] > 2]]] /@ {l1, l2, l3}



Only top voted, non community-wiki answers of a minimum length are eligible