New answers tagged

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}
eldo's user avatar
  • 48.3k
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] <...
eldo's user avatar
  • 48.3k
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}
halmir's user avatar
  • 14.8k
0 votes

Making some powers of variables inside the function : $X * \alpha^{m} *\beta^{n} f[A[x,y]] \Rightarrow X f[\alpha^{m}\beta^{n} A[x,y]]$

...
Bob Hanlon's user avatar
  • 152k
4 votes

Concise alternative to First@First@Position[..., 1,Heads->False]

Another way, is to use PositionIndex and KeySelect: ...
E. Chan-López's user avatar
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 ...
bmf's user avatar
  • 13k
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) ...
eldo's user avatar
  • 48.3k
3 votes

How to implement JoinTo efficiently?

We can also use ApplyTo (new in 12.2) together with Splice (new in 12.1): ...
eldo's user avatar
  • 48.3k
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 ...
Alex Trounev's user avatar
  • 41.9k
1 vote

Selecting positive real numbers from a list?

list = {1, 11.2, -12, a, 10 + I}; You can use DeleteCases as follows: ...
E. Chan-López's user avatar
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 ...
eldo's user avatar
  • 48.3k
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} ...
eldo's user avatar
  • 48.3k
1 vote

How to efficiently Append a result of an operation on each element of a list to itself?

Using Cases: ...
E. Chan-López's user avatar
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 ...
Daniel Lichtblau's user avatar
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}} *) ...
user1066's user avatar
  • 15.6k
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} *)
user1066's user avatar
  • 15.6k
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!
Alexei Boulbitch's user avatar
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): ...
Henrik Schumacher's user avatar
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 ...
eldo's user avatar
  • 48.3k
3 votes

Accumulated instance count of each list element

Another way using PositionIndex and ReplacePart: ...
E. Chan-López's user avatar
4 votes

Accumulated instance count of each list element

Just more variations... ...
lericr's user avatar
  • 24.5k
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} *)
vindobona's user avatar
  • 1,681
2 votes

How to add a column to a dataset made up of an association of associations?

...
eldo's user avatar
  • 48.3k
6 votes

Accumulated instance count of each list element

Using an Association - counter: ...
eldo's user avatar
  • 48.3k
3 votes

How to add a column to a dataset made up of an association of associations?

ds[All, Module[{$c = 0}, <|"ID" -> ++$c, #|> &]] ...
kglr's user avatar
  • 384k
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 ...
Daniel Huber's user avatar
  • 47.2k
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} ...
kglr's user avatar
  • 384k
5 votes

Manipulate list of equations

MultiplySides[#,Denominator[First@#],Assumptions->Denominator[First@#]>0]&/@eqns (*{a ==b c, d == e f, x == y z} *)
user1066's user avatar
  • 15.6k
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] ...
user64494's user avatar
  • 24.3k
8 votes
Accepted

Accumulated instance count of each list element

...
Syed's user avatar
  • 41.7k
3 votes

How to remove a high accuracy numerical number from a list?

Using Cases and FractionalPart: ...
E. Chan-López's user avatar
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 ...
bmf's user avatar
  • 13k
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, ...
Syed's user avatar
  • 41.7k
3 votes

Finding position of the maximum value of each subset

We could also use TakeLargest ...
eldo's user avatar
  • 48.3k
0 votes

Easier way to input Dynamic matrix?

This Exemple calculate Dynamicly a Determinant with PopupMenu: ...
Reda.Kebbaj's user avatar
1 vote

Comparing Positions of Elements in a List

Using Mr. Wizard's data: list = Characters @ "xdslkridiatjxzyoedem"; we can use PositionIndex to our advantage ...
eldo's user avatar
  • 48.3k
1 vote

Ordering function with recognition of duplicates

Using Association - related functions (which were not available at the time the question was posted): ...
eldo's user avatar
  • 48.3k
0 votes

Subtracting second columns of two matrices

Using Transpose and MapAt: ...
E. Chan-López's user avatar
1 vote

Subtracting second columns of two matrices

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

Retrieving duplicates from nested list

Using Cases: ...
E. Chan-López's user avatar
2 votes

Retrieving duplicates from nested list

Using some functions which were not availabe at the time the question was posed ...
eldo's user avatar
  • 48.3k
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: ...
eldo's user avatar
  • 48.3k
2 votes

How do I check if any element in a list is positive?

A point-free style {-1, -1, 1} // AnyTrue[Positive]
AsukaMinato's user avatar
  • 8,815
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 ...
eldo's user avatar
  • 48.3k
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: ...
Sjoerd Smit's user avatar
  • 21.9k
0 votes

Counting the population of integers

Another possibility: ...
user1066's user avatar
  • 15.6k
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, ...
Syed's user avatar
  • 41.7k
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,...
eldo's user avatar
  • 48.3k
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]
lericr's user avatar
  • 24.5k
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: ...
march's user avatar
  • 22.9k

Top 50 recent answers are included