Skip to main content

New answers tagged

1 vote

How to select 2 pairs of distinct twins form a list of 4-tuples?

data = Tuples[Range @ 6, 4]; Using Cases with OrderlessPatternSequence ...
eldo's user avatar
  • 75.1k
1 vote

Manipulation of two lists of strings and integers

...
eldo's user avatar
  • 75.1k
0 votes

How to retrieve the index of a subset in Subsets[list,nspec,{s}]?

You can use Combinatorica Package by evaluating (without "") "<<Combinatorica`". Then use RankKSubset like so: ...
azerbajdzan's user avatar
  • 18.9k
1 vote

Take elements from a list based on two criteria

list = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}, {1, (1 + I)/Sqrt[2]}}; A variant of 1066's answer using Cases ...
eldo's user avatar
  • 75.1k
1 vote

Sublist pattern matching

list = {{1, 2, 3}, {1, 2, 3}, {1, 2, 2, 3}, {1, 3, 3, 5}}; Using SequenceSplit (new in 11.3) ...
eldo's user avatar
  • 75.1k
3 votes

Extract result of Reap in a natural way no matter if it's empty

Sow the magic disappearing list element Nothing as the first thing in the Reap block: ...
John Doty's user avatar
  • 13.8k
2 votes

Mathematica values new list

Using Pick ...
RGL's user avatar
  • 101
2 votes

Is there a simple way to generate a non-uniformly divided interval according to an arbitrary division function?

To explain the idea, we first do the opposite of what you want. We get a high density of points where ndivFunc is small and low density where ndivFunc is high, we integrate ndivFunc. This gives a ...
Daniel Huber's user avatar
  • 52.7k
1 vote

Multiple calculations in a condition

A pedestrian answer with the two interpretations: ...
ubpdqn's user avatar
  • 61.6k
3 votes

Multiple calculations in a condition

list = {1, 2, 3, 82, 84, 1}; p = Position[list, x_ /; x > 3] {{4}, {5}} Erase <= 3 ...
eldo's user avatar
  • 75.1k
2 votes

Removing lists with zero at any position

list = Tuples[Range[-2, 2], 2]; Using Pick and ContainsNone (new in 10.2) ...
eldo's user avatar
  • 75.1k
1 vote

Appending to sublists using "anchor" values

Using GroupBy and Splice (new in 12.1) ...
eldo's user avatar
  • 75.1k
2 votes

Constructing a list

array = {{1, 2, 3, 4, 5}, {5, 6, 7, 8, 9}, {9, 10, 11, 12, 13}}; Catenate@MapThread[List, {Array[List, Dimensions@#], #}, 2] &@array {{{1, 1}, 1}, {{1, 2}, 2}...
vindobona's user avatar
  • 4,651
1 vote

Extraction of sublists from a list

Using SequencePosition on string list ...
RGL's user avatar
  • 101
2 votes

Constructing a list

data = Partition[Range[9], 3]; Using ReplaceAt (new in 13.1) and Outer ...
eldo's user avatar
  • 75.1k
1 vote

ListLinePlot without joined the data point

data = {{0, 0}, {0.5, 2}, {1, 5}, {2, 8.5}, {4, 10}, {0, 0}, {0.5, 4}, {1, 7}, {2, 9.5}, {4, 12}, {0, 0}, {0.5, 5}, {1, 9}, {2, 12}, {4, 18}}; Using <...
eldo's user avatar
  • 75.1k
3 votes

Subtract more than one array using DeleteCases

a = {9, 4, 7, 1, 5, 3, 8, 5, 7, 3, 1, 0}; b = {7, 5}; c = {8, 3}; Using Pick and FreeQ <...
eldo's user avatar
  • 75.1k
3 votes

How can I change elements in a matrix to a combination of other elements?

list = {{x1, y1, z1}, {x2, y2, z2}, {x3, y3, z3}}; Using ReplaceAll ...
eldo's user avatar
  • 75.1k
2 votes

Extract result of Reap in a natural way no matter if it's empty

A data-set-like approach: ...
Goofy's user avatar
  • 3,092
6 votes

Extract result of Reap in a natural way no matter if it's empty

Using the second argument of First: First[Reap[a][[2]],{}] (* {} *)
Lukas Lang's user avatar
  • 34.1k
4 votes

Extract result of Reap in a natural way no matter if it's empty

Rather than make assumptions about structure, I'd recommend building in your updating process to the Reap explicitly. Here are a couple of ways: 1. Use tags and a ...
lericr's user avatar
  • 29.2k
4 votes

Extract result of Reap in a natural way no matter if it's empty

Reap[Sow[a]; b; Sow[c]; Sow[d]; e, {_}, Splice[#2] &][[2, 1]] (* {a, c, d} *) ...
user1066's user avatar
  • 19.6k
4 votes

Extract result of Reap in a natural way no matter if it's empty

If you just want to make a list of sown values, how about using Flatten? ...
A. Kato's user avatar
  • 489
3 votes

Extract result of Reap in a natural way no matter if it's empty

How about defining a helper function?: Clear[fix]; fix[{a_, {b_List}}] := {a, b} fix[expr_] := expr Usage: ...
xzczd's user avatar
  • 66.9k
4 votes

How to add zeros before and after each element in a list?

Using Splice list={0.2,0.5,0.7}; Take[Riffle[list, Splice[{0, 0}], {1, -1, 2}], {2, -2}];
RGL's user avatar
  • 101
2 votes

Replace elements of a list based on a function

Also: f = Table[3*k*k, {k, 1, 16}]; f^ ArrayPad[{1, 1, 1, 1, 0, 0, 0, 0}, {0, Length@f - 8}, "Periodic"] ...
vindobona's user avatar
  • 4,651
2 votes

Replace elements of a list based on a function

f = Table[3*k*k, {k, 1, 16}]; Using SequenceCases ...
eldo's user avatar
  • 75.1k
1 vote

How to substitute Table environments by a more sophisticated code

list = Range[12, 30]; Using SequenceCases ...
eldo's user avatar
  • 75.1k
2 votes

How to use `StringJoin` in the given example?

list = {{"abc", "0000"}, {"def", "1111"}}; Using the operator form of Insert ...
eldo's user avatar
  • 75.1k
4 votes

Recovering indices from an expression

For expr = U[1, 3] U[1, 4] U[1, 5] U[2, 2] U[3, 1]; you can do {firstindex, secondindex} = Transpose[List @@@ List @@ expr] or ...
march's user avatar
  • 23.8k
3 votes

Recovering indices from an expression

Given, expression = U[1, 3] U[1, 4] U[1, 5] U[2, 2] U[3, 1] you could use Cases: ...
lericr's user avatar
  • 29.2k
4 votes

Recovering indices from an expression

Oh dear... I was working too hard. This will do it. ...
ZeroTheHero's user avatar
1 vote

How do I remove parts of this data?

list = {{9.9, 0}, {"", ""}, {10.0, -21.7}, {"", ""}, {10.0, 28.5}, {"", ""}}; Using ...
eldo's user avatar
  • 75.1k
1 vote

How to make an element in a list nested within a list have a default value?

list = {{{-2, -2}, 1}, {{-2, -5}, 2, 7}, {{1, 5}, 3, 9}, {{7, -7}, 4}}; Using ReplaceAll ...
eldo's user avatar
  • 75.1k
1 vote

Find list position and mapping list

...
eldo's user avatar
  • 75.1k
0 votes

Applying function to lists

list = {0.67, 0.89, 0.70, 0.78, 0.54}; n = 17; ...
eldo's user avatar
  • 75.1k
2 votes

Replacing a sub-partition (unordered list; multiset)

list = {{4, 4, 2, 2, 1, 1, 1}, {4, 4, 2, 2, 2, 1}}; A variant of 1066's answer using SequenceReplace (new in 11.3) ...
eldo's user avatar
  • 75.1k
3 votes

How can I construct this matrix?

n = 5; Table[RotateRight[Range[n], i], {i, 0, n - 1}] // MatrixForm ...
eldo's user avatar
  • 75.1k
1 vote

List of symbols wherein position encoded by number to string

list = {{"a", 6}, {"z", 1}, {"g", 2}, {"y", 12}}; Using SubsetMap (new in 12.0) ...
eldo's user avatar
  • 75.1k
2 votes

Creating a new list from an existing one

data = { {{1, -1}, {2, 5}, {3, 9}, {4, 2}}, {{1, -4}, {2, 0}, {3, 11}, {4, -1}}, {{1, 3}, {2, 2}, {3, 22}, {4, 1}}, {{1, 0}, {2, 0}, {3, -5}, {4, 7}} }; ...
eldo's user avatar
  • 75.1k
2 votes

Finding position of non empty matrix entries

list = {{}, {1, 2}, {}, {3, 4}, {}, {}, {}}; Using Position and DeleteCases ...
eldo's user avatar
  • 75.1k
0 votes

Need list of unequal lengths to be paired with year

SeedRandom[0]; a = Range[1990, 1991]; b = {RandomReal[{0, 1}, 2], RandomReal[{0, 1}, 3]}; n = Length[a]; Using Table ...
eldo's user avatar
  • 75.1k
2 votes

Creating a conditional table

list = {7, 0, 8, 2, 1, 5, 8, 0, 6, 7}; Using FirstPosition (new in 10.0) to catch missing values 1. The 3rd parameter of ...
eldo's user avatar
  • 75.1k
2 votes

Delete sublists of list with given properties

...
eldo's user avatar
  • 75.1k
2 votes

How to leave only specific columns?

...
eldo's user avatar
  • 75.1k
1 vote

How to create an array from all combinations of the vector components?

la = {a, b, c}; lb = {w, x, y, z}; A variant of E. Chan-López first answer using Comap (new in 14.0) ...
eldo's user avatar
  • 75.1k
3 votes

Get alphabetical number of characters in string

str = "abcdefghijklmnopqrstuvwxyz"; Using LetterNumber (new in 10.1) ...
eldo's user avatar
  • 75.1k
3 votes

Counting consecutive units in nested lists

If we look at your problem in a simplistic manner, we could see a function that increments by receiving 1 and resets by receiving 0 (like multiplying but with an increment). Since we need the result ...
Ben Izd's user avatar
  • 9,319
4 votes
Accepted

Counting consecutive units in nested lists

Using LongestCommonSubsequence ...
vindobona's user avatar
  • 4,651
5 votes

Counting consecutive units in nested lists

Max /@ Total[(Split /@ lst), {3}] (* {2, 3, 5, 7, 13} *) ...
user1066's user avatar
  • 19.6k

Top 50 recent answers are included