New answers tagged list-manipulation
1
vote
Measuring multiple incidences of a continuous constant in a list
Using SequenceSplit (new in 11.3)
list = {{0}, {1}, {1}, {0}, {1}, {0}};
Length /@ SequenceSplit[list, {{0}}]
{2, 1}
0
votes
Translate selection from one list to another
KeySelect is another possibility
al = {1, 2, 3, 4, 5, 6};
bl = {a, b, c, d, e, f};
KeySelect[EvenQ] @ Thread[al -> bl]
<...
3
votes
How can I determine the cycle lengths in a directed graph?
a = {{0, 1, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 1}, {1, 0, 0, 0}};
g = AdjacencyGraph[a];
Length /@ FindCycle[g, Infinity, All]
{3, 4}
0
votes
4
votes
Concise alternative to First@First@Position[..., 1,Heads->False]
Another way, is to use PositionIndex and KeySelect:
...
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
...
3
votes
Concise alternative to First@First@Position[..., 1,Heads->False]
If we don't have negative numbers (thank you 1066) we can use
PositionLargest (new in 13.2)
...
3
votes
How to implement JoinTo efficiently?
We can also use ApplyTo (new in 12.2) together with Splice (new in 12.1):
...
2
votes
Taylor approximation of integrals
I found one scheme that converges, but with not very high accuracy. Note that increasing the number of terms of the series and the number of iterations does not reduce the error. It is possible that ...
1
vote
Selecting positive real numbers from a list?
list = {1, 11.2, -12, a, 10 + I};
You can use DeleteCases as follows:
...
1
vote
Selecting positive real numbers from a list?
list = {1, 11.2, -12, a, 10 + I};
If we treat 1 as as a real number, we can use ...
1
vote
Count consecutive occurrences in a list above a certain value
Using SequenceSplit which came with V 11.3
Length /@ SequenceSplit[data, {x_ /; x < 100}]
{3, 2}
...
1
vote
2
votes
Taylor approximation of integrals
There are some typos in your equations if what you want to reproduce is table 2 and figure 1. In particular the alpha parameter is 20, not 0.2, the ...
1
vote
How to efficiently Append a result of an operation on each element of a list to itself?
lst={{x1, y1, z1}, {x2, y2, z2},{x3,y3,z3}}
MapThread[Append,{#,#[[All,2]] #[[All,3]]}]&@lst
(*{{x1,y1,z1,y1 z1},{x2,y2,z2,y2 z2},{x3,y3,z3,y3 z3}} *)
...
2
votes
Accumulated instance count of each list element
MapThread[Replace[#1,#2]&,{list,Counts@Take[list,#]&/@Range@Length@list}]
(* {1,1,1,2,2,3,4,3,1,2,4} *)
1
vote
Manipulate list of equations
eqns = {a/b == c, d/e == f, x/y == z};
eqns /. u_/v_ == w_ -> u == w*v
(* {a == b c, d == e f, x == y z} *)
Have fun!
1
vote
How to efficiently Append a result of an operation on each element of a list to itself?
This is basically the same as Rojo's idea, but it appears to be 10% faster on my system (M1 Max):
...
2
votes
How to efficiently Append a result of an operation on each element of a list to itself?
list = {{a, b, c}, {e, f, g}};
Splice came with V 12.1
...
3
votes
Accumulated instance count of each list element
Another way using PositionIndex and ReplacePart:
...
4
votes
5
votes
Accumulated instance count of each list element
list = {m, i, s, s, i, s, s, i, p, p, i};
Permute[Flatten[Ordering /@ Split@Sort@#], Ordering@#]&@list
(* {1, 1, 1, 2, 2, 3, 4, 3, 1, 2, 4} *)
6
votes
3
votes
How to add a column to a dataset made up of an association of associations?
ds[All,
Module[{$c = 0}, <|"ID" -> ++$c, #|> &]]
...
4
votes
How to add a column to a dataset made up of an association of associations?
You can add items using Prepend/Append like e.g. to add an ID number:
c = 1;
ds = Prepend[#, ID -> c++] & /@ baseDeDatos
Note that MMA now displays the ...
11
votes
Accumulated instance count of each list element
accumulateCounts := Module[{c$}, c$[_] = 0; Map[PreIncrement@*c$]]
accumulateCounts @ {m, i, s, s, i, s, s, i, p, p, i}
...
5
votes
Manipulate list of equations
MultiplySides[#,Denominator[First@#],Assumptions->Denominator[First@#]>0]&/@eqns
(*{a ==b c, d == e f, x == y z} *)
3
votes
Manipulate list of equations
One of the ways is as follows.
eqns = {a/b == c, d/e == f, x/y == z}; Map[#[[1]]/#[[1, 2]] == #[[2]]/#[[1, 2]] &, eqns]
...
8
votes
Accepted
3
votes
How to remove a high accuracy numerical number from a list?
Using Cases and FractionalPart:
...
6
votes
How to remove a high accuracy numerical number from a list?
Not very elegant, but since you explicitly mention that you want to remove 0.2499999999999992
...
6
votes
How to remove a high accuracy numerical number from a list?
list = {-0.36, 0.2499999999999992, -0.21, 0.36, 0.36}
Delete[list,
Position[Round[list, 0.01] - list, Except[0.], {1, ∞},
Heads -> False]]
{-0.36, -0.21, ...
3
votes
0
votes
Easier way to input Dynamic matrix?
This Exemple calculate Dynamicly a Determinant with PopupMenu:
...
1
vote
Comparing Positions of Elements in a List
Using Mr. Wizard's data:
list = Characters @ "xdslkridiatjxzyoedem";
we can use PositionIndex to our advantage
...
1
vote
Ordering function with recognition of duplicates
Using Association - related functions (which were not available at the time the question was posted):
...
0
votes
1
vote
2
votes
2
votes
Retrieving duplicates from nested list
Using some functions which were not availabe at the time the question was posed
...
3
votes
Selecting a sublist based on Length
We could also use TakeLargestBy
list = {{1, 2}, {4, 5, 6, 7}, {5, 4, 3}};
Take the largest list by length:
...
2
votes
How do I check if any element in a list is positive?
A point-free style
{-1, -1, 1} // AnyTrue[Positive]
2
votes
How do I check if any element in a list is positive?
Since V 10.0 we can also use AnyTrue:
AnyTrue[{-1, -1, 1}, # > 0 &]
True
...
1
vote
Counting the population of integers
This has a lot of answers already, but here's an obvious (to me) solution that hasn't been mentioned:
...
0
votes
0
votes
Neglecting coefficients of a given list
Clear["Global`*"];
exp1 = a1*a2*24 + a1*a2*a3*kk*25 + a1*a2^2 + a1*a2*a3*34;
DeleteCases[List @@ exp1, _?NumericQ | kk, {2}]
{a1 a2, a1 a2^2, a1 a2 a3, ...
1
vote
Numbering element in descending order
Since V 12.0 there is OrderingBy:
m = {{1, 5}, {2, 8}, {3, 9}, {4, 2}, {5, 9}, {6, 7}, {7, 9}, {8, 10}, {9, 5}, {10, 2}};
Ordering @ OrderingBy[Last] @ m
{3, 6, 7,...
3
votes
How do I create a list of matrices based on lists I have?
a = {1, 2, 3};
b = {4, 5, 6};
Transpose@MapThread[List, {{n^2 - b^2, a*b}, {b*a, n^2 - a^2}}, 2]
4
votes
Accepted
How do I create a list of matrices based on lists I have?
One can do one of the three following, among others:
...
Top 50 recent answers are included
Related Tags
list-manipulation × 9399plotting × 826
matrix × 772
performance-tuning × 534
functions × 438
filtering × 420
replacement × 286
pattern-matching × 270
function-construction × 264
string-manipulation × 225
programming × 207
data × 201
equation-solving × 194
map × 186
sorting × 167
graphics × 158
import × 145
combinatorics × 133
functional-style × 122
export × 121
associations × 118
differential-equations × 113
output-formatting × 111
manipulate × 107
conditional × 107