Tag Info

New answers tagged

1

I post this as another answer (using again $ 3p3=p1+p2-5$) if the matrices are the main aim: sa0 = SparseArray[{i_, j_} :> (i - 1) (j - 1), {3, 3}] // MatrixForm; sa = SparseArray[{{i_, j_} /; ((i - 1) (j - 1) != 0) :> (i - 1) (j - 1), {i_, j_} /; ((i - 1) ( j - 1) == 0) :> (i + j + 5)/3.}, {3, 3}] // MatrixForm; Row[{sa0, ...


2

Your p3 definitions seem different. The following uses 3p3 -5=p1+p2. set = Tuples[Range[0, 2], 2]; set /. {x_, y_} :> (x + y + 5)/3. /; x y == 0 yields: {1.66667, 2., 2.33333, 2., {1, 1}, {1, 2}, 2.33333, {2, 1}, {2, 2}} or if you wish to couple results and {p1,p2}: set /. {{x_, y_} :> Rule[{x, y}, (x + y + 5)/3.] /; x y == 0, {x_, y_} :> ...


3

For your second question, you could use (tabletry = Table[p1*p2, {p1, 0, 2}, {p2, 0, 2}]) // MatrixForm; (* or (tabletry = Array[# #2 &, {3, 3}, 0]) // MatrixForm; *) (tst = Map[{# == 0} &, tabletry, {-1}]) // MatrixForm or (tst2 = Array[# #2 /. {0 -> {True}, _ -> {False}} &, {3, 3}, 0]) // MatrixForm Note the parantheses wrapping ...


6

First, your construction of f is a bit malformed. You are using the operator form of Select, therefore the Select expression itself acts as a function; you do not need to add @# & to it. Use instead: f = Select[#[[2]] >= 10 &]; The reason that your operations are not the same can be seen by mapping a dummy function foo: foo /@ a <|1 ...


4

Load Simon Woods's smartThread from: How can I make threading more flexible? Write simply: smartThread[tensorR + tensorS, 1] Be happy. :-)


6

Here is a way to use MapThread: MapThread[Function[{r, s}, r + # & /@ s], {tensorR, tensorS}, 2] For numeric tensors, it can be compiled to squeeze out a little more performance: Compile[{{tensorR, _Real, 3}, {tensorS, _Real, 4}} , MapThread[Function[{r, s}, r + # & /@ s], {tensorR, tensorS}, 2] ] Performance Measurements @kguler's solution ...


4

Use the second argument of Transpose: transpose the last two levels of tensorS, add tensorR, transpose the last two levels again: tensorS = Array[Subscript[s, #1, #2, #3, #4] &, {2, 16, 16, 19}]; tensorR = Array[Subscript[r, #1, #2, #3] &, {2, 16, 19}]; opres = Table[Map[Plus[tensorR[[i, j]], #]&, tensorS[[i, j]], {1}], {i, 1, 2}, {j, 1, 16}]; ...



Top 50 recent answers are included