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 |
Results tagged with list-manipulation
Search options not deleted
user 53427
Questions on the manipulation of List objects in Mathematica, and the functions used for these manipulations.
2
votes
2
answers
62
views
A question about Ordering command
We have the following list:
list={a,b,c};
Subsequently, we apply the Ordering command to the permutations of the previous list, and we obtain the following:
Permutations[{a, b, c}]
(*{{a, b, c}, {a, …
6
votes
Sort nested list by a fixed order
Something like the following:
Map[Sort[#] &, list]
(*{{{a, 1}, {b, 3}, {c, 5}}, {{a, 5}, {b, 1}, {c, 3}}, {{a, 5}, {b, 3}, {c, 1}}, {{a, 1}, {b, 5}, {c, 3}}}*)
A first approximation:
MyOrderList[list …
3
votes
Delete columns of table where the sum of column adds to zero
Another possibility is to use SequenceCases:
data = {{1, 0, 1, 0, 1}, {2, 0, 2, 0, 2}, {3, 0, 3, 0, 3}, {4, 0, 4, 0, 4}, {5, 0, 5, 0, 5}};
Transpose[Map[If[SequenceCases[#, list_ /; Total[list] =!= …
3
votes
Modify one list according to degeneracies of another
My attempt for your problem is as follows:
ReplaceByDegeneracy[listA_, listB_] := Block[{dupA, posA, extractB, arrayB},
dupA = Mean[Flatten[Map[If[#[[1]] === #[[2]], #, Nothing] &,
DeleteDuplicates[S …
3
votes
How to apply a logical operation to all expressions in a list
Another way:
Reduce[{xP == 1 + x, yP == 3 + y}, {xP, yP}]
(*xP == 1 + x && yP == 3 + y*)
8
votes
Joining sublists of nested list based on sublist position
Another approach using Delete, Extract and Insert:
Insert[Delete[list, #], Join @@ Extract[list, #], 4] & @@ {{{4}, {5}}}
(*{{a, b, c, d}, {e, f}, {g, h, i}, {j, k, l}, {m, n, o}}*)
2
votes
Combining a list with a certain index of a list
Just for fun, the following puzzle in the form of code works:
ArrayReshape[Map[Flatten@Append[#[[1]], #[[2]]] &, Level[Map[Thread, Thread[Map[Composition[Transpose, List, ConstantArray[#, Mean[Map[Len …
2
votes
How to find a median of odd and even numbers from a list of numbers
Try Cases:
list={94, 35, 47, 29, 86, 40, 46, 72, 87};
twolists=List[Cases[list, Except[_?EvenQ]], Cases[list, Except[_?OddQ]]]
(*{{35, 47, 29, 87}, {94, 86, 40, 46, 72}}*)
Map[Median, twolists]
(*{41, …
6
votes
Accepted
Write the result of expression to a list
As @LouisB comments, using Table:
f[n_] := 2 Cos[n π/3]
Table[f[n], {n, 1, 100}]
(*{1, -1, -2, -1, 1, 2, 1, -1, -2, -1, 1, 2, 1, -1, -2, -1, 1, 2, 1,
-1, -2, -1, 1, 2, 1, -1, -2, -1, 1, 2, 1, -1, …
5
votes
Accepted
Is there a way of column-based ArrayReshape
Try this:
Transpose[ArrayReshape[Range[10], Reverse[{2, 5}]]]
(*{{1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}}*)
2
votes
Add quotes to each element in a list
My attempt is the following:
ToSubscriptHoldForm[expr_?VectorQ] := Block[{asymb, asub},
asymb = Array[Subscript[ToExpression["a"], #] &, 2, 1];
asub = Array[Subscript[ToExpression["a"], #] &, 2, 1, Ho …
1
vote
How can I multiply only a few columns of a table by some number in a compact way?
Building a MultiplyByPosition function:
MultiplyByPosition[array_?VectorQ, factor_, positions : {___Integer}] :=
ReplacePart[array, Thread[Rule[Nest[Map[List, #] &, positions, 2],
Flatten[factor*Ext …
4
votes
Removing missing data from a list
Another way is as follows:
DeleteCases[Map[If[NumericQ[#] === True, #, Nothing] &, data, {-1}], {}]
(*{{0.04, 22.4, 43.286, 99.998}, {0.04, 22.4, 43.288, 99.997}, {0.04, 22.4, 43.289, 99.997}, {588.2 …
2
votes
How do I substitute lists in list?
Using Apply, Function and Part (as pointed out @bmf):
Apply[Function[{p1, p2, p3}, {p1[[1]] + p2[[1]] + p3[[1]], p2[[2]], p2[[3]] + p3[[3]]}], {a, b, c}]
(*{4, 1, 5}*)
Just to expand on @lericr's ans …
3
votes
Delete columns of table where the sum of column adds to zero
Another approach is the following:
data = {{1, 0, 1, 0, 1}, {2, 0, 2, 0, 2}, {3, 0, 3, 0, 3}, {4, 0, 4, 0, 4}, {5, 0, 5, 0, 5}};
Transpose[Map[If[Total[data[[All, #]]] === 0, Nothing, data[[All, #]] …