# Search Results

Results tagged with
Search options not deleted user 53427
68 results

Questions on the manipulation of List objects in Mathematica, and the functions used for these manipulations.

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,919

### 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 …
• 6,919

### 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] =!= …
• 6,919

### 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 …
• 6,919

### 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*)
• 6,919

### 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}}*)
• 6,919

### 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 …
• 6,919

### 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,919
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, …
• 6,919
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}}*)
• 6,919

### 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 …
• 6,919
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 …
• 6,919

### 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 …
• 6,919