Hot answers tagged

10

tl;dr If these functions cannot decide, they will simply return False. A False result means that the selected equality testing method wasn't able to prove equality, but it does not mean that it was able to prove inequality. Interpret the result relative to the used SameTest option value. I will try to explain what I think is happening, though some of ...


10

wrap the matrix rows with the the Flatten function M = {{{1}, {2}, {3}, {4}}, {{5}, {6}, {7}, {8}}} To save time you can wrap your whole matrix using: Map[Flatten, <yourmatrix> ] Map[Flatten,{{{1}, {2}, {3}, {4}}, {{5}, {6}, {7}, {8}}}] the outermost list contains two elements (the rows). the Map function wraps these elements with the ...


9

Lots of solutions. Time for a benchmark. My own contribution is Part: m = {{{1}, {2}, {3}}, {{2}, {4}, {6}}}; m[[All, All, 1]]; {{1, 2, 3}, {2, 4, 6}} Update: I made a complete mess of my earlier attempt at benchmarking. Here is a rewrite. methods = Hold[Flatten /@ m, ArrayReshape[m, Most@Dimensions@m], ArrayReshape[m, Dimensions[m][[1 ;; ...


7

You can use ArrayReshape. Either ArrayReshape[mat, Most@Dimensions@mat] or ArrayReshape[mat, Dimensions[mat][[1 ;; 2]]] It will keep a packed array packed, too.


6

Edit With m = RandomInteger[9, {3, 6, 1}] Just for completeness: Catenate /@ m Just for diversity reasons Apply[#&, m, {2}] Apply[Sequence, m, {-2}] Map[First, m, {2}] Using @Mr.Wizard code I have updated the benchmark. @MichaelE2 also noticed in comments that Catenate is not compilable.


5

You can also Apply Join at level 1 to your list: m = RandomInteger[9, {2, 4, 1}] {{{0}, {6}, {7}, {5}}, {{1}, {3}, {8}, {8}}} Join @@@ m {{0, 6, 7, 5}, {1, 3, 8, 8}}


5

Here's a nice one-liner: TransformationFunction[{{1, 0, 0, 0}, {0, 0, -1, 0}, {0, 1, 0, 3}, {0, 0, 0, 1}}] // InverseFunction TransformationFunction[{{1, 0, 0, 0}, {0, 0, 1, -3}, {0, -1, 0, 0}, {0, 0, 0, 1}}] Note that TransformationFunction[] is the head of the results returned by geometric *Transform functions, which take a homogeneous transformation ...


4

If you have a homogenous transformation matrix of the form $$\begin{bmatrix} \mathrm{R_{3 \times 3}} & \mathrm{d}_{3 \times 1} \\ 0_{1\times 3} & 1_{1\times 1} \end{bmatrix}$$ Then the inverse is given by $$\begin{bmatrix} \mathrm{R}^{-1} & -\mathrm{R}^{-1}\mathrm{d} \\ 0 & 1 \end{bmatrix}$$ Therefore, if your ...


3

I suggest Flatten[m, {Depth[m] - 1, 1}], where m is the matrix in question. For example, SeedRandom[1]; m = RandomInteger[99, {4, 5, 1}] {{{80}, {14}, {0}, {67}, {3}}, {{65}, {23}, {97}, {68}, {74}}, {{15},{24}, {4}, {90}, {83}}, {{70}, {1}, {30}, {48}, {25}}} Flatten[m, {Depth[m] - 1, 1}] {{80, 14, 0, 67, 3}, {65, 23, 97, 68, 74}, {15, ...


2

You cannot use @ as it is used for assignments etc. So just set up your own tensor product tp and inner product ip and define tp[id,v_]:=v tp[v_,id]:=v Tra[tp[a,b]]:=ip[a,b] Trans[tp[a,b]]:=tp[b,a] ip[tp[a,b],tp[c,d]]:=ip[b,c] tp[a,d] and tp[a_+b_,c_]:=tp[a,c]+tp[b,c] It is unclear as to what you mean by "respect scalar multiplication". If you only ...


1

n=2; A = ConstantArray[1, {n, n}]; B = ConstantArray[2, {n, n}]; Y = ConstantArray[3, {n, n}]; Z = ConstantArray[0, {n, n}]; ClearAll[a, b, y, z] m = 10; mat=Normal@SparseArray[{{i_,i_}->a,{i_,j_}/;i-j==1->b,{i_,j_}/;j-i 1->y,{i_,j_}/;Abs[i-j]>1->z},{m,m}] ArrayFlatten[mat /. {a -> A, b -> B, y -> Y, z -> Z}]


1

The solution to your Eigenvalues function are Root objects, see the documentation. Root[f,k] represents the exact k^(th) root of the polynomial equation f[x]==0. Inside Root is the pure function in the argument #1. If we named this pure function f with argument x, this would correspond to the situation in the above quote with f[x]. Your Matrix $A$ ...



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