Skip to main content
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
Search options not deleted user 251

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

7 votes

Changing sign of elements of a list on even positions

This is one way: MapIndexed[{n, pos} |-> If[ EvenQ @ Last @ pos, -n, n], list, {2}]
Gustavo Delfino's user avatar
6 votes

Insert a list within another without extra brackets

Using Sequence (for older versions of WL without Splice): list1 = {{1, -1.1}, {2, -1}, {3, -0.9}, {4, 0}, {10, -0.4}}; list2 = {{2, -0.6}, {3, -0.6}}; Insert[list1, Inactive[Sequence] @@ list2, 3] // …
Gustavo Delfino's user avatar
1 vote

Pairing headers with each subsequent entry in a flattened list

This is based on @Swish answer, but keeping everything string based: With[{separatorQ = StringMatchQ["a-" ~~ DigitCharacter]}, Flatten[ SequenceCases[ oldList, { left : _Stri …
Gustavo Delfino's user avatar
4 votes

Map-Thread-Through-Apply a list of functions onto a list of (lists of) values

Yet another solution: Transpose[Activate[Thread[Inactive[Map][fns, Transpose[list]]]]]
Gustavo Delfino's user avatar
4 votes

Creating a list with Thread

I think that the most natural way of doing this is by using MapIndexed. But if you want to use Range and Thread, this is one way: {{11, 21, 31}, {12, 22, 32}, {13, 23, 33}} // {Length /* Range, Iden …
Gustavo Delfino's user avatar
4 votes

Span a function across several consecutive elements in a list

How about this way: spanMap[f_, list_, {start_, end_}] := Replace[ MapAt[f, list, List /@ Range[start, end]] /. {x___Integer, seq : (PatternSequence[f[_] ..]), y___Integer} :> {x, {seq …
Gustavo Delfino's user avatar
7 votes

Manipulating Elements in a Triple-Nested List

This command may be helpful to you: MapAt[2 # &, {{{44.5, 0.00185}, {45.2, 0.00186}, {45.5, 0.00186}}, {{48.6, 0.00186}, {49.2, 0.00209}, {49.9, 0.00109}}}, {All, All, 2}] It produces this outpu …
Gustavo Delfino's user avatar
2 votes

Selecting list elements depending if they contain sub-list elements

It is also possible by using rules: cc /. {s_Symbol, pair_List} /; !MemberQ[Join[aa, bb], pair] -> Nothing
Gustavo Delfino's user avatar
2 votes

Extract output from FindMaximum inside a function

Perhaps it is more intuitive if we use rules: FindMaximum[{3 x, x < 1}, x] /. {result_, {x -> _}} -> result
Gustavo Delfino's user avatar
2 votes

Duplicating entry values of a list to match varying number of sublist entries

How about: Flatten[abc /. {x_Integer, {y : _List ...}} :> Thread[{x, Join@y}], 1] (* {{{1, 1}, {1, 2}}, {{2, 3}, {2, 4}, {2, 5}}, {{3, 2}}} *)
Gustavo Delfino's user avatar
1 vote

Pure function on pure function

This is one way: Map[max |-> SelectFirst[t1, # > max &], t2] and another way as three separate functional operations: t2 // Map[GreaterThan/*SelectFirst] // OperatorApplied[Construct][t1] // Th …
Gustavo Delfino's user avatar
1 vote

How to show the whole table

This is one way: {{7, 6}, {2, 4}} // ReplaceAll[v_?VectorQ :> (v /. Min[v] -> Item[Min[v], Background -> Red])] // Legended[Grid[#, Dividers -> All], SwatchLegend[{Red}, {"minimum"}]] &
Gustavo Delfino's user avatar
4 votes

Transform sequence into ragged list

Lets process this using Fold. We will replace each number with a list consisting of the number, and its depth: g[{level_, current_List}, element_Integer] := {level, Append[current, {element, level}]} …
Gustavo Delfino's user avatar
4 votes

How to remove extra brackets from a list?

Can also be done like this: Query[All, Splice][list1]
Gustavo Delfino's user avatar
3 votes
4 answers
137 views

Deleting or replacing inner elements depending on higher level elements

Consider a data structure like: data = {{"experiment"->1, "tags"->{"type"->1}, "results"->{{"x", 2}, {"y", 5}, {"z", 5}}}, {"experiment"->2, "tags"->{"type"->2}, "results"->{{"x", 1}, {"y", 2 …
Gustavo Delfino's user avatar

15 30 50 per page