Skip to main content
added 45 characters in body
Source Link
march
  • 24.2k
  • 2
  • 46
  • 102

Here's some ways. Using:

l = {1+2*s,2+3*s,4+1*s};
slist = {1, 2, 3};

The answer closest to what you asked is

{1 + 2*s, 2 + 3*s, 4 + 1*s} /. s -> slist // Diagonal

However, that does 3^2 - 3 too many calculations, so here's some more ways:.

Module[{i = 1}, l /. s :> slist[[i++]]]
MapThread[#1 /. s -> #2 &, {l, slist}]
MapThread[ReplaceAll, {l, Thread[s -> slist]}]
ReplaceAll @@@ Transpose[{l, Thread[s -> slist]}]
Map[First@#1 /. s -> Last@#1 &, Transpose@{l, slist}]
MapIndexed[#1 /. s -> slist[[First@#2]] &, l]

If s is always going to be the list {1, 2, 3, ...}, then:

MapIndexed[#1 /. s -> First@#2 &, l]

Here's some ways. Using:

l = {1+2*s,2+3*s,4+1*s};
slist = {1, 2, 3};

The answer closest to what you asked is

{1 + 2*s, 2 + 3*s, 4 + 1*s} /. s -> slist // Diagonal

However, that does 3^2 - 3 too many calculations, so here's some more ways:

MapThread[#1 /. s -> #2 &, {l, slist}]
MapThread[ReplaceAll, {l, Thread[s -> slist]}]
ReplaceAll @@@ Transpose[{l, Thread[s -> slist]}]
Map[First@#1 /. s -> Last@#1 &, Transpose@{l, slist}]
MapIndexed[#1 /. s -> slist[[First@#2]] &, l]

If s is always going to be the list {1, 2, 3, ...}, then:

MapIndexed[#1 /. s -> First@#2 &, l]

Here's some ways. Using:

l = {1+2*s,2+3*s,4+1*s};
slist = {1, 2, 3};

The answer closest to what you asked is

{1 + 2*s, 2 + 3*s, 4 + 1*s} /. s -> slist // Diagonal

However, that does 3^2 - 3 too many calculations, so here's some more ways.

Module[{i = 1}, l /. s :> slist[[i++]]]
MapThread[#1 /. s -> #2 &, {l, slist}]
MapThread[ReplaceAll, {l, Thread[s -> slist]}]
ReplaceAll @@@ Transpose[{l, Thread[s -> slist]}]
Map[First@#1 /. s -> Last@#1 &, Transpose@{l, slist}]
MapIndexed[#1 /. s -> slist[[First@#2]] &, l]

If s is always going to be the list {1, 2, 3, ...}, then:

MapIndexed[#1 /. s -> First@#2 &, l]
deleted 7 characters in body
Source Link
march
  • 24.2k
  • 2
  • 46
  • 102

Here's some ways. Using:

l = {1+2*s,2+3*s,4+1*s};
slist = {1, 2, 3};

The answer closest to what you asked is

{1 + 2*s, 2 + 3*s, 4 + 1*s} /. s -> slist // Diagonal

However, that does 3^2 - 3 too many calculations, so here's some more ways:

MapThread[#1 /. s -> #2 &, {l, slist}]
MapThread[ReplaceAll, {l, Thread[s -> slist]}]
ReplaceAll @@@ Transpose[{l, Thread[s -> slist]}]
MapIndexed[First@#1Map[First@#1 /. s -> Last@#1 &, Transpose@{l, slist}]
MapIndexed[#1 /. s -> slist[[First@#2]] &, l]

If s is always going to be the list {1, 2, 3, ...}, then:

MapIndexed[#1 /. s -> First@#2 &, l]

Here's some ways. Using:

l = {1+2*s,2+3*s,4+1*s};
slist = {1, 2, 3};

The answer closest to what you asked is

{1 + 2*s, 2 + 3*s, 4 + 1*s} /. s -> slist // Diagonal

However, that does 3^2 - 3 too many calculations, so here's some more ways:

MapThread[#1 /. s -> #2 &, {l, slist}]
MapThread[ReplaceAll, {l, Thread[s -> slist]}]
ReplaceAll @@@ Transpose[{l, Thread[s -> slist]}]
MapIndexed[First@#1 /. s -> Last@#1 &, Transpose@{l, slist}]
MapIndexed[#1 /. s -> slist[[First@#2]] &, l]

If s is always going to be the list {1, 2, 3, ...}, then:

MapIndexed[#1 /. s -> First@#2 &, l]

Here's some ways. Using:

l = {1+2*s,2+3*s,4+1*s};
slist = {1, 2, 3};

The answer closest to what you asked is

{1 + 2*s, 2 + 3*s, 4 + 1*s} /. s -> slist // Diagonal

However, that does 3^2 - 3 too many calculations, so here's some more ways:

MapThread[#1 /. s -> #2 &, {l, slist}]
MapThread[ReplaceAll, {l, Thread[s -> slist]}]
ReplaceAll @@@ Transpose[{l, Thread[s -> slist]}]
Map[First@#1 /. s -> Last@#1 &, Transpose@{l, slist}]
MapIndexed[#1 /. s -> slist[[First@#2]] &, l]

If s is always going to be the list {1, 2, 3, ...}, then:

MapIndexed[#1 /. s -> First@#2 &, l]
added 133 characters in body
Source Link
march
  • 24.2k
  • 2
  • 46
  • 102

Here's some ways. Using:

l = {1+2*s,2+3*s,4+1*s};
slist = {1, 2, 3};

The answer closest to what you asked is

{1 + 2*s, 2 + 3*s, 4 + 1*s} /. s -> slist // Diagonal

However, that does 3^2 - 3 too many calculations, so here's some more ways:

MapThread[#1 /. s -> #2 &, {l, slist}]
ReplaceAll @@@MapThread[ReplaceAll, Transpose[{l, Thread[s -> slist]}]
{1 + 2*s, 2ReplaceAll +@@@ 3*sTranspose[{l, 4 + 1*s} /. sThread[s -> slist // Diagonalslist]}]
MapIndexed[First@#1 /. s -> Last@#1 &, Transpose@{l, slist}]
MapIndexed[#1 /. s -> slist[[First@#2]] &, l]

If s is always going to be the list {1, 2, 3, ...}, then:

MapIndexed[#1 /. s -> First@#2 &, l]

Here's some ways:

l = {1+2*s,2+3*s,4+1*s};
slist = {1, 2, 3};

MapThread[#1 /. s -> #2 &, {l, slist}]
ReplaceAll @@@ Transpose[{l, Thread[s -> slist]}]
{1 + 2*s, 2 + 3*s, 4 + 1*s} /. s -> slist // Diagonal
MapIndexed[First@#1 /. s -> Last@#1 &, Transpose@{l, slist}]
MapIndexed[#1 /. s -> slist[[First@#2]] &, l]

If s is always going to be the list {1, 2, 3, ...}, then:

MapIndexed[#1 /. s -> First@#2 &, l]

Here's some ways. Using:

l = {1+2*s,2+3*s,4+1*s};
slist = {1, 2, 3};

The answer closest to what you asked is

{1 + 2*s, 2 + 3*s, 4 + 1*s} /. s -> slist // Diagonal

However, that does 3^2 - 3 too many calculations, so here's some more ways:

MapThread[#1 /. s -> #2 &, {l, slist}]
MapThread[ReplaceAll, {l, Thread[s -> slist]}]
ReplaceAll @@@ Transpose[{l, Thread[s -> slist]}]
MapIndexed[First@#1 /. s -> Last@#1 &, Transpose@{l, slist}]
MapIndexed[#1 /. s -> slist[[First@#2]] &, l]

If s is always going to be the list {1, 2, 3, ...}, then:

MapIndexed[#1 /. s -> First@#2 &, l]
Source Link
march
  • 24.2k
  • 2
  • 46
  • 102
Loading