Hot answers tagged

5

The main issue and its solution are discussed in Do Table iteration variables need to be localized using Module? In short, using Module is the correct way to guard against accidental variable name collisions. Addressing some of the comments from the linked question: Adding an explicit use of Block will not change the situation because Sum and Table ...


2

Here is one way to do it dataset = { <|"user" -> "vinayak", "event" -> "joined", "ts" -> RandomInteger[10]|>, <|"user" -> "vinayak", "event" -> "left", "ts" -> RandomInteger[10]|>, <|"user" -> "vishal", "event" -> "joined", "ts" -> RandomInteger[10]|>, <|"user" -> "vishal", "event" -> "...


2

You can use TableForm: TableForm[Join @@ Table[{i, j, 10 i + j}, {i, 4}, {j, 3}], TableHeadings -> {None, {i, j, f[i, j]}}, TableAlignments -> Center] or replace TableForm with MatrixForm to get: Alternatively, you can use Grid: Grid[Prepend[Join @@ Table[{i, j, 10 i + j}, {i, 4}, {j, 3}], {i, j, f[i, j]}], Alignment -> {Center, Center}]


2

i = 1; Table[i++, {j, 1, 4}] {1, 2, 3, 4} h = 1; ParallelTable[h++, {j, 1, 4}] {1, 1, 1, 1}


1

If you want to loop over what would be the result of Tuples[s, {n}] without generating all tuples at once, then you need to recall that tuple generation is isomorphic to generating $n$-digit base-$b$ numbers, where b == Length[s]: n = 3; s = {0, 1}; b = Length[s]; Do[Print[s[[IntegerDigits[k, b, n] + 1]]], {k, 0, b^n - 1}] Otherwise, there is the option of ...


1

A more functional solution Transpose[{x, StandardQuickSort[[6 ;; 6 + Length@x - 1]]}] (* {{1, 89097}, {2, 170994}, {3, 7567432}, {4, 34201637}, {5, 83379287}} *)


1

First off, your indexing in Table is problematic. If you look at the documentation for the Table command, you'll see that when you pass three values to Table for the range, it interprets it as: {i,i_min,i_max} so in your case this would be "Take i from 6 to 5", hence you have no output in your table. One way you can accomplish what you're looking for is ...


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