51
votes
Accepted
Is there a built-in equivalent to Python's enumerate?
Streaming` module - general, and the case at hand
Starting with V10.1, there is an undocumented support for certain lazy operations in Mathematica. However, the ...
46
votes
Accepted
Why do Mathematica list indices start at 1?
I think Leonid's answer deserves to be expanded upon. Most other languages are not symbolic, and thus the "variable name" is not something one needs to keep track of --- ultimately the interpreted or ...
45
votes
How to understand the usage of Inner and Outer figuratively?
Animated Mathematica Functions contains cool animated illustrations of the way a number of built-in functions work. Among them are
Thread
Inner:
Outer
See also: cormullion's video
44
votes
Accepted
How to implement the general array broadcasting method from NumPy?
Broadcasting vs Listability
NumPy broadcasting lets you perform, in efficient way, element-wise operations on arrays, as long as dimensions of those arrays are considered "compatible" in some sense.
...
36
votes
Accepted
Apply multiple functions to same list
Also,
y = {1, 2, 3, 4, 5, 6, 7};
#[y] & /@ {Max, Min, Median, Mean}
(* {7, 1, 4, 4} *)
EDIT: comparing the timings:
...
35
votes
Selecting every n-th element from a list
Please look up Part and Span.
You can use
data[[ ;; ;; n]]
34
votes
Accepted
DeleteDuplicatesBy is not performing as I'd hoped. Am I missing something?
The behavior described here is the same from 10.0.0 up to at least 10.3.
Summary
We can look at the code of DeleteDuplicatesBy and it turns out it uses ...
33
votes
Apply multiple functions to same list
You can use Through.
Through[{Max, Min, Median, Mean}[y]]
(* {7, 1, 4, 4} *)
Hope this helps.
33
votes
Accepted
Why it seems that there is no counterpart function as to multiplication, to `Total` as to addition?
In addition to the previous answer...
I designed and implemented Total 17 years ago. Its first version was named ListSum. The ...
31
votes
How to subtract the column means from each row of a matrix?
It is there:
Standardize[mat, Mean, 1 &]

Kuba♦
- 133k
31
votes
Accepted
Can Mathematica put these puzzle pieces together?
Assuming polygons follow the same (clockwise or counterclockwise) vertex order, find all good quality two line segment rigid mappings between polygons without overlap with each other (at least much ...
30
votes
Accepted
Is there a way to riffle more than two lists?
{{a, b, c}, {1, 2, 3}, {x, y, z}} ~Flatten~ {2, 1}
{a, 1, x, b, 2, y, c, 3, z}
30
votes
Accepted
Add a vector to a list of vectors
I recommend using Transpose twice since it is more efficient than other approaches. Moreover Plus has the ...
30
votes
Accepted
Mysterious behaviour of Pick
This is not a bug. It is a consequence of the manner in which Pick scans its arguments.
The Pick Process
The documentation ...
29
votes
What is a Mathematica packed array?
I would like to point out that Listable in a pure Function effectively unpacks the array, and makes it much slower than Map for ...
29
votes
Accepted
How to understand the usage of Inner and Outer figuratively?
I think of Outer just like nikie showed.
Inner is a generalization of matrix multiplication. I like the picture from the ...
29
votes
How do you concatenate matrices? And how do you make block matrices?
As Daniel Lichtblau suggested in the comment, ArrayFlatten is the way.
ArrayFlatten[{{A1, A2}}] // MatrixForm gives your ...
29
votes
How to implement the general array broadcasting method from NumPy?
Challenging NumPy's performance will be extremely difficult, and thus the effort of implementing this is not likely to be worthwhile. The reason is that the multiple-transpose method, even though it ...
29
votes
Cyclic Take function?
A variation on Szabolcs's suggestion:
overTake = PadRight[##, "Periodic"] &;
overTake[{1, 2}, 5]
{1, 2, 1, 2, 1}
28
votes
Accepted
Performance of Select
res1 = Select[coordinates, #[[1]] > 6 && #[[1]] < 7 &]; //
AbsoluteTiming // First
6.997629
...
27
votes
Accepted
Solving and Animating Three Body Problem
Generally always check Demonstrations site for good code. I cannot not mention an excellent "classic" of planar three body problem by Stephen Wolfram and Michael Trott. Code is short and I verified it ...
26
votes
Accepted
Partition on sublists beginning with a certain marker elements
Split[list, (#2 =!= {a}) &]
...

Kuba♦
- 133k
26
votes
Accepted
Partitioning a list when the cumulative sum exceeds 1
dat = {0.71, 0.685, 0.16, 0.82, 0.73, 0.44, 0.89, 0.02, 0.47, 0.65};
Module[{t = 0},
Split[dat, (t += #) <= 1 || (t = 0) &]
]
...
26
votes
Accepted
How was Nothing implemented?
Ok, I failed to find a duplicate so here is my comment:
I don't know how Nothing is internally implemented but you can do something like this with ...

Kuba♦
- 133k
26
votes
Accepted
How to replace all elements of a list by a rule "element" -> "element_"
Here is one way:
Pattern[#, Blank[]] & /@ {a, b, c, d, e, f, g, h, i, j}
(* {a_, b_, c_, d_, e_, f_, g_, h_, i_, j_} *)
An inspection of the ...
25
votes
Permutations[Range[12]] produces an error instead of a list
Since Mathematica 8 it is possible generate the elements of any group one by one with GroupElements. Here's for example a randomly chosen element of the permutation ...
25
votes
Partitioning with varying partition size
New in 11.2 is TakeList:
TakeList[Range[10], {2, 3, 5}]
{{1, 2}, {3, 4, 5}, {6, 7, 8, 9, 10}}
25
votes
Converting a list of rules to a list of lists
list = {"Joe" -> 94, "Jane" -> 85, "Bob" -> 82, "Bill" -> 83, "Michelle" -> 98};
List @@@ list
{{"Joe", 94}, {"Jane", 85}, {"Bob", 82}, {"Bill", ...
25
votes
How to subtract the column means from each row of a matrix?
Well, transposing, subtracting, transposing...
Transpose[Transpose[mat] - Mean[mat]]
25
votes
Accepted
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
list-manipulation × 7641matrix × 627
plotting × 585
performance-tuning × 432
filtering × 372
functions × 356
table × 281
pattern-matching × 242
replacement × 235
function-construction × 213
string-manipulation × 188
programming × 186
array × 153
map × 152
data × 148
sorting × 139
equation-solving × 124
combinatorics × 120
import × 109
graphics × 108
functional-style × 103
associations × 98
manipulate × 86
graphs-and-networks × 81
random × 81