How to multiply nested lists by a list with the same length?
up vote
2
down vote
favorite
Here's the expected output:
{{a, b}, {c, d}, {e, f}} * {3, 4} = {{3a, 4b}, {3c, 4d}, {3e, 4f}}
However, the code above will multiply each element of the encompassing list (3 elements) by {3, 4}
(2 elements) and cause an error.
I've tried defining a function and using Map
, but I'm sure there's a more elegant way of doing this speedily, without needing to first define a function.
list-manipulation
add a comment |
up vote
2
down vote
favorite
Here's the expected output:
{{a, b}, {c, d}, {e, f}} * {3, 4} = {{3a, 4b}, {3c, 4d}, {3e, 4f}}
However, the code above will multiply each element of the encompassing list (3 elements) by {3, 4}
(2 elements) and cause an error.
I've tried defining a function and using Map
, but I'm sure there's a more elegant way of doing this speedily, without needing to first define a function.
list-manipulation
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Here's the expected output:
{{a, b}, {c, d}, {e, f}} * {3, 4} = {{3a, 4b}, {3c, 4d}, {3e, 4f}}
However, the code above will multiply each element of the encompassing list (3 elements) by {3, 4}
(2 elements) and cause an error.
I've tried defining a function and using Map
, but I'm sure there's a more elegant way of doing this speedily, without needing to first define a function.
list-manipulation
Here's the expected output:
{{a, b}, {c, d}, {e, f}} * {3, 4} = {{3a, 4b}, {3c, 4d}, {3e, 4f}}
However, the code above will multiply each element of the encompassing list (3 elements) by {3, 4}
(2 elements) and cause an error.
I've tried defining a function and using Map
, but I'm sure there's a more elegant way of doing this speedily, without needing to first define a function.
list-manipulation
list-manipulation
edited 1 hour ago
kglr
173k8195400
173k8195400
asked 1 hour ago
WeavingBird1917
1395
1395
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
4
down vote
accepted
{3, 4} # & /@ {{a, b}, {c, d}, {e, f}}
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
Alternative forms:
Map[{3, 4} # &][{{a, b}, {c, d}, {e, f}}]
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
Map[{3, 4} # &, {{a, b}, {c, d}, {e, f}}]
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
1
Works perfectly. If anyone else is wondering, the multiplication sign is not required here, but you can also modify this to perform other basic operations such as addition by placing the operator between the slot:{3, 4} + #
. Or to add subtract square root:{3, 4} - Sqrt[#]
.
– WeavingBird1917
1 hour ago
add a comment |
up vote
1
down vote
{{a, b}, {c, d}, {e, f}}.DiagonalMatrix[{3, 4}]
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
add a comment |
up vote
0
down vote
Dear @WeavingBird1917 you can use Table for your purpose.
list={{a, b}, {c, d}, {e, f}};
result=Table[
{3*list[[i,1]],4*list[[i,2]]}
,{i,1,Length[list]}
]
If you want to change multiplication with summation, subtraction or division, you need only change the * sign with +, - or /.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
{3, 4} # & /@ {{a, b}, {c, d}, {e, f}}
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
Alternative forms:
Map[{3, 4} # &][{{a, b}, {c, d}, {e, f}}]
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
Map[{3, 4} # &, {{a, b}, {c, d}, {e, f}}]
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
1
Works perfectly. If anyone else is wondering, the multiplication sign is not required here, but you can also modify this to perform other basic operations such as addition by placing the operator between the slot:{3, 4} + #
. Or to add subtract square root:{3, 4} - Sqrt[#]
.
– WeavingBird1917
1 hour ago
add a comment |
up vote
4
down vote
accepted
{3, 4} # & /@ {{a, b}, {c, d}, {e, f}}
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
Alternative forms:
Map[{3, 4} # &][{{a, b}, {c, d}, {e, f}}]
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
Map[{3, 4} # &, {{a, b}, {c, d}, {e, f}}]
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
1
Works perfectly. If anyone else is wondering, the multiplication sign is not required here, but you can also modify this to perform other basic operations such as addition by placing the operator between the slot:{3, 4} + #
. Or to add subtract square root:{3, 4} - Sqrt[#]
.
– WeavingBird1917
1 hour ago
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
{3, 4} # & /@ {{a, b}, {c, d}, {e, f}}
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
Alternative forms:
Map[{3, 4} # &][{{a, b}, {c, d}, {e, f}}]
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
Map[{3, 4} # &, {{a, b}, {c, d}, {e, f}}]
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
{3, 4} # & /@ {{a, b}, {c, d}, {e, f}}
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
Alternative forms:
Map[{3, 4} # &][{{a, b}, {c, d}, {e, f}}]
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
Map[{3, 4} # &, {{a, b}, {c, d}, {e, f}}]
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
edited 1 hour ago
answered 1 hour ago
kglr
173k8195400
173k8195400
1
Works perfectly. If anyone else is wondering, the multiplication sign is not required here, but you can also modify this to perform other basic operations such as addition by placing the operator between the slot:{3, 4} + #
. Or to add subtract square root:{3, 4} - Sqrt[#]
.
– WeavingBird1917
1 hour ago
add a comment |
1
Works perfectly. If anyone else is wondering, the multiplication sign is not required here, but you can also modify this to perform other basic operations such as addition by placing the operator between the slot:{3, 4} + #
. Or to add subtract square root:{3, 4} - Sqrt[#]
.
– WeavingBird1917
1 hour ago
1
1
Works perfectly. If anyone else is wondering, the multiplication sign is not required here, but you can also modify this to perform other basic operations such as addition by placing the operator between the slot:
{3, 4} + #
. Or to add subtract square root: {3, 4} - Sqrt[#]
.– WeavingBird1917
1 hour ago
Works perfectly. If anyone else is wondering, the multiplication sign is not required here, but you can also modify this to perform other basic operations such as addition by placing the operator between the slot:
{3, 4} + #
. Or to add subtract square root: {3, 4} - Sqrt[#]
.– WeavingBird1917
1 hour ago
add a comment |
up vote
1
down vote
{{a, b}, {c, d}, {e, f}}.DiagonalMatrix[{3, 4}]
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
add a comment |
up vote
1
down vote
{{a, b}, {c, d}, {e, f}}.DiagonalMatrix[{3, 4}]
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
add a comment |
up vote
1
down vote
up vote
1
down vote
{{a, b}, {c, d}, {e, f}}.DiagonalMatrix[{3, 4}]
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
{{a, b}, {c, d}, {e, f}}.DiagonalMatrix[{3, 4}]
{{3 a, 4 b}, {3 c, 4 d}, {3 e, 4 f}}
answered 30 mins ago
Henrik Schumacher
45.7k466132
45.7k466132
add a comment |
add a comment |
up vote
0
down vote
Dear @WeavingBird1917 you can use Table for your purpose.
list={{a, b}, {c, d}, {e, f}};
result=Table[
{3*list[[i,1]],4*list[[i,2]]}
,{i,1,Length[list]}
]
If you want to change multiplication with summation, subtraction or division, you need only change the * sign with +, - or /.
add a comment |
up vote
0
down vote
Dear @WeavingBird1917 you can use Table for your purpose.
list={{a, b}, {c, d}, {e, f}};
result=Table[
{3*list[[i,1]],4*list[[i,2]]}
,{i,1,Length[list]}
]
If you want to change multiplication with summation, subtraction or division, you need only change the * sign with +, - or /.
add a comment |
up vote
0
down vote
up vote
0
down vote
Dear @WeavingBird1917 you can use Table for your purpose.
list={{a, b}, {c, d}, {e, f}};
result=Table[
{3*list[[i,1]],4*list[[i,2]]}
,{i,1,Length[list]}
]
If you want to change multiplication with summation, subtraction or division, you need only change the * sign with +, - or /.
Dear @WeavingBird1917 you can use Table for your purpose.
list={{a, b}, {c, d}, {e, f}};
result=Table[
{3*list[[i,1]],4*list[[i,2]]}
,{i,1,Length[list]}
]
If you want to change multiplication with summation, subtraction or division, you need only change the * sign with +, - or /.
answered 1 hour ago
Hadi Sobhani
1746
1746
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f186847%2fhow-to-multiply-nested-lists-by-a-list-with-the-same-length%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown