Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Questions on the manipulation of List objects in Mathematica, and the functions used for these manipulations.
3
votes
Accepted
Two lists into Table form
Transpose @ {xvalues,yvalues}
or
Thread@{xvalues, yvalues}
both give
{{75.618, 0.999907}, {77.2612, 0.999932}, {78.9044,
0.999953}, {80.5477, 0.999969}, {82.1909, 0.99998}, {83.8341,
0.999989}, {85 …
2
votes
Replace Parts in List with Parts from other List
The answer by @lericr is optimal with regards to minimality and I like it a lot. Another way to go about it is the following:
t1 = {{1, 2}, {3, 4}, {5, 6}};
t2 = {a, b, c};
ArrayReshape[Riffle[First …
1
vote
Replace Parts in List with Parts from other List
An alternative way
t1 = {{1, 2}, {3, 4}, {5, 6}};
t2 = {a, b, c};
list = Flatten[MapThread[List, {t1, #}] &@t2];
Partition[Drop[list, {2, Length@list, 3}], 2]
Edit: thanks to @lericr for the relevant …
5
votes
Accepted
I have a list of 175 elements. Each element contains two numbers. I want to pick those eleme...
With a list
list = RandomReal[{1, 10}, {10, 2}]
{{8.25097, 4.41379}, {4.96729, 3.19113}, {1.31825, 6.73581}, {9.18737,
9.23329}, {2.27443, 2.6997}, {1.86022, 5.05654}, {8.64963,
7.68031}, {2.03275, …
7
votes
Accepted
Using Reap instead of AppendTo
The following works and reproduces precisely the result of the OP.
f[x_, y_, z_] := (y + z^2) Exp[-I x] + (x + z^2) Exp[-I y];
g[x_, y_, z_] := Abs[Conjugate[f[x, y, z]]*f[x + 1, y + 1, z + 2]];
Code …
2
votes
How can I change some numbers in a list?
Some more.
With
a = Range[10]
we can use the command Clip as follows:
Clip[#, {-Infinity, 5}, {0, # + 1}] & /@ a
another way using ReplacePart
ReplacePart[#, Position[#, x_ /; x > 5] -> # + 1] & /@ …
6
votes
Delete duplicates element sublist
Ok, since @E. Chan-López gave the proper answer let's see with what else we can come up.
Suggested solution
Gather[Sort /@ l1][[All, 1]]
Comparison with the DeleteDuplicates solution
DeleteDuplicates[ …
2
votes
Using MapThread on list of lists
All the normal looking answers have been given.
Given a list
lst = {{{1, 2}, {a, b}}, {{3, 4}, {c, d}}};
we can use
ArrayReshape[
Inner[Rule, Select[lst // Flatten, Head[#] == Integer &],
Transpo …
4
votes
Concise alternative to First@First@Position[..., 1,Heads->False]
Hats off to @eldo for the amazing work on revisiting old threads to demonstrate commands in newer versions. I think it's very beneficial for all.
Some more fun stuff
With the list
list = {0, 0, 7};
f …
3
votes
Adding 1 to all second elements
Supporting @eldo in an effort of good house maintenance as much as I can.
We can use Query
Query[All, {1 -> ( # + {0, 1} &)}]@list
{{{5, 2}}, {{2, 2}, {3, 2}}, {{7, 2}}, {{2, 4}}}
3
votes
Join lists in a list of lists
Trying to keep up with @eldo
We can use FoldPairList + TakeDrop which were both introduced in v10.2
Join @@@ FoldPairList[TakeDrop, {{1}, {2}, {3}, {4}}, {1, 2, All}]
to give
{{1}, {2, 3}, {4}}
or …
1
vote
Select subsets of elements of a list under a certain condition
For educational/illustrational purposes and to connect to the beautiful answer by @elso consider the following
testfunction = Total[#[[All, 2]]] >= 1000 &;
We can use Cases
Cases[Subsets@list, argume …
3
votes
How do you efficiently return all of a list but one element?
An update from v13.1 worth adding here is DeleteElements
With a list
list = RandomInteger[{-1, 11}, 13]
{8, 7, 0, 10, 3, 0, 7, 2, 3, 5, -1, 3, 3}
let's say that we want to remove the number 3 altog …
1
vote
How to find intersection of multiple lists excluding empty ones?
We can, also, use UniqueElements that came with v13.1
DeleteDuplicates[
Flatten[{List /@ a, List /@ b, List /@ c} /.
Flatten[Thread[UniqueElements[{a, b, c}] -> #] & @@ {placeholder},
2]] …
2
votes
Modify all the second elements of every pair in a list of pairs
Using ReplacePart
index = 1;
ReplacePart[list, {_, 2} :> Standardize[list[[All, 2]]][[index++]]]
Edit: an equivalent way of writing the above is, thanks to @eldo
ReplacePart[list, {i_, 2} :> Standard …