Multiplying elements of a listReplace elements in a listList of lengths of runs of elementsMaking a list of...
Cryptic cross... with words
Do error bars on probabilities have any meaning?
How can I use a Module anonymously as the function for /@?
Boss asked me to sign a resignation paper without a date on it along with my new contract
Are all power cords made equal?
Using font-relative distances in tikzpictures
Can you wish for more wishes from an Efreeti bound to service via an Efreeti Bottle?
Arizona laws regarding ownership of ground glassware for chemistry usage
Can "ee" appear in Latin?
Identical projects by students at two different colleges: still plagiarism?
What does @ mean in a hostname in DNS configuration?
Last Reboot commands don't agree
Is Screenshot Time-tracking Common?
How can I make my enemies feel real and make combat more engaging?
What does "don't have a baby" imply or mean in this sentence?
Why is Shelob considered evil?
Why would you use 2 alternate layout buttons instead of 1, when only one can be selected at once
Microphone on Mars
Will linear voltage regulator step up current?
How bad is a Computer Science course that doesn't teach Design Patterns?
The Late Queen Gives in to Remorse - Reverse Hangman
Why is quixotic not Quixotic (a proper adjective)?
How to play songs that contain one guitar when we have two or more guitarists?
Why Third 'Reich'? Why is 'reich' not translated when 'third' is? What is the English synonym of reich?
Multiplying elements of a list
Replace elements in a listList of lengths of runs of elementsMaking a list of rules from the list of elementsMultiplying columns of a list of matricesHow to list ArrayFilter?Selecting elements from lists of a listAdding $y$ values based on the value of $x$ in a listExtracting the elements from a loop of sets/ listsAdding each element in a list to the previous onecontrariwise multiplying a list into each raw of a matrix
$begingroup$
Given I have a following list of numbers:
l={2,3,4,5,6}
I wonder how to multiply each number by the one before of it,
such that I get
{2*3,2*3*4,2*3*4*5,...}
Also how can I chose a level for this operation?
by level I mean,
level 1 : 2*3
level 2 : 2*3*4
and so on.
list-manipulation multiplcation
$endgroup$
add a comment |
$begingroup$
Given I have a following list of numbers:
l={2,3,4,5,6}
I wonder how to multiply each number by the one before of it,
such that I get
{2*3,2*3*4,2*3*4*5,...}
Also how can I chose a level for this operation?
by level I mean,
level 1 : 2*3
level 2 : 2*3*4
and so on.
list-manipulation multiplcation
$endgroup$
add a comment |
$begingroup$
Given I have a following list of numbers:
l={2,3,4,5,6}
I wonder how to multiply each number by the one before of it,
such that I get
{2*3,2*3*4,2*3*4*5,...}
Also how can I chose a level for this operation?
by level I mean,
level 1 : 2*3
level 2 : 2*3*4
and so on.
list-manipulation multiplcation
$endgroup$
Given I have a following list of numbers:
l={2,3,4,5,6}
I wonder how to multiply each number by the one before of it,
such that I get
{2*3,2*3*4,2*3*4*5,...}
Also how can I chose a level for this operation?
by level I mean,
level 1 : 2*3
level 2 : 2*3*4
and so on.
list-manipulation multiplcation
list-manipulation multiplcation
asked 3 hours ago
WilliamWilliam
79248
79248
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
$begingroup$
FoldList[Times, l] (* or *)
FoldList[Times]@l
{2, 6, 24, 120, 720}
Also:
Exp @ Accumulate @ Log @ l
{2, 6, 24, 120, 720}
$endgroup$
add a comment |
$begingroup$
list = Range[2, 6]
(* {2, 3, 4, 5, 6} *)
To keep the factors separate, use Inactive
with kglr's solution
list2 = Rest@FoldList[Inactive@Times, list[[1]], Rest@list]
Activate
produces the result
list3 = list2 // Activate
(* {6, 24, 120, 720} *)
Or use NonCommutativeMultiply
to hold the factors
list4 = Rest@FoldList[NonCommutativeMultiply, list[[1]], Rest@list]
(* {2 ** 3, 2 ** 3 ** 4, 2 ** 3 ** 4 ** 5, 2 ** 3 ** 4 ** 5 ** 6} *)
Then Apply
Times
to get the final result
list5 = Times @@@ list4
(* {6, 24, 120, 720} *)
For this specific case (sequential numbers), the result is just Factorial
list3 == list5 == Factorial /@ Rest@list
(* True *)
Use Part
to access any element of the result, e.g.,
list3[[1]]
(* 6 *)
$endgroup$
add a comment |
$begingroup$
This can also be solved using recursion. The function cumProd (cumulative product) can be defined as:
list = Range[10];
cumProd[n_] := cumProd[n - 1]*list[[n]];
cumProd[1] = list[[1]];
To use:
cumProd[6]
720
gives the 6th "level" of the product. Of course, list can be any set of numbers. Applying this to the whole list:
cumProd/@Range[Length[list]]
{1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800}
$endgroup$
add a comment |
$begingroup$
here is your level function
level[x_] := Times @@ l[[;; x + 1]];
level[1]
level[2]
6
24
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f191937%2fmultiplying-elements-of-a-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
FoldList[Times, l] (* or *)
FoldList[Times]@l
{2, 6, 24, 120, 720}
Also:
Exp @ Accumulate @ Log @ l
{2, 6, 24, 120, 720}
$endgroup$
add a comment |
$begingroup$
FoldList[Times, l] (* or *)
FoldList[Times]@l
{2, 6, 24, 120, 720}
Also:
Exp @ Accumulate @ Log @ l
{2, 6, 24, 120, 720}
$endgroup$
add a comment |
$begingroup$
FoldList[Times, l] (* or *)
FoldList[Times]@l
{2, 6, 24, 120, 720}
Also:
Exp @ Accumulate @ Log @ l
{2, 6, 24, 120, 720}
$endgroup$
FoldList[Times, l] (* or *)
FoldList[Times]@l
{2, 6, 24, 120, 720}
Also:
Exp @ Accumulate @ Log @ l
{2, 6, 24, 120, 720}
edited 2 hours ago
answered 3 hours ago
kglrkglr
185k10202420
185k10202420
add a comment |
add a comment |
$begingroup$
list = Range[2, 6]
(* {2, 3, 4, 5, 6} *)
To keep the factors separate, use Inactive
with kglr's solution
list2 = Rest@FoldList[Inactive@Times, list[[1]], Rest@list]
Activate
produces the result
list3 = list2 // Activate
(* {6, 24, 120, 720} *)
Or use NonCommutativeMultiply
to hold the factors
list4 = Rest@FoldList[NonCommutativeMultiply, list[[1]], Rest@list]
(* {2 ** 3, 2 ** 3 ** 4, 2 ** 3 ** 4 ** 5, 2 ** 3 ** 4 ** 5 ** 6} *)
Then Apply
Times
to get the final result
list5 = Times @@@ list4
(* {6, 24, 120, 720} *)
For this specific case (sequential numbers), the result is just Factorial
list3 == list5 == Factorial /@ Rest@list
(* True *)
Use Part
to access any element of the result, e.g.,
list3[[1]]
(* 6 *)
$endgroup$
add a comment |
$begingroup$
list = Range[2, 6]
(* {2, 3, 4, 5, 6} *)
To keep the factors separate, use Inactive
with kglr's solution
list2 = Rest@FoldList[Inactive@Times, list[[1]], Rest@list]
Activate
produces the result
list3 = list2 // Activate
(* {6, 24, 120, 720} *)
Or use NonCommutativeMultiply
to hold the factors
list4 = Rest@FoldList[NonCommutativeMultiply, list[[1]], Rest@list]
(* {2 ** 3, 2 ** 3 ** 4, 2 ** 3 ** 4 ** 5, 2 ** 3 ** 4 ** 5 ** 6} *)
Then Apply
Times
to get the final result
list5 = Times @@@ list4
(* {6, 24, 120, 720} *)
For this specific case (sequential numbers), the result is just Factorial
list3 == list5 == Factorial /@ Rest@list
(* True *)
Use Part
to access any element of the result, e.g.,
list3[[1]]
(* 6 *)
$endgroup$
add a comment |
$begingroup$
list = Range[2, 6]
(* {2, 3, 4, 5, 6} *)
To keep the factors separate, use Inactive
with kglr's solution
list2 = Rest@FoldList[Inactive@Times, list[[1]], Rest@list]
Activate
produces the result
list3 = list2 // Activate
(* {6, 24, 120, 720} *)
Or use NonCommutativeMultiply
to hold the factors
list4 = Rest@FoldList[NonCommutativeMultiply, list[[1]], Rest@list]
(* {2 ** 3, 2 ** 3 ** 4, 2 ** 3 ** 4 ** 5, 2 ** 3 ** 4 ** 5 ** 6} *)
Then Apply
Times
to get the final result
list5 = Times @@@ list4
(* {6, 24, 120, 720} *)
For this specific case (sequential numbers), the result is just Factorial
list3 == list5 == Factorial /@ Rest@list
(* True *)
Use Part
to access any element of the result, e.g.,
list3[[1]]
(* 6 *)
$endgroup$
list = Range[2, 6]
(* {2, 3, 4, 5, 6} *)
To keep the factors separate, use Inactive
with kglr's solution
list2 = Rest@FoldList[Inactive@Times, list[[1]], Rest@list]
Activate
produces the result
list3 = list2 // Activate
(* {6, 24, 120, 720} *)
Or use NonCommutativeMultiply
to hold the factors
list4 = Rest@FoldList[NonCommutativeMultiply, list[[1]], Rest@list]
(* {2 ** 3, 2 ** 3 ** 4, 2 ** 3 ** 4 ** 5, 2 ** 3 ** 4 ** 5 ** 6} *)
Then Apply
Times
to get the final result
list5 = Times @@@ list4
(* {6, 24, 120, 720} *)
For this specific case (sequential numbers), the result is just Factorial
list3 == list5 == Factorial /@ Rest@list
(* True *)
Use Part
to access any element of the result, e.g.,
list3[[1]]
(* 6 *)
answered 1 hour ago
Bob HanlonBob Hanlon
60.5k33597
60.5k33597
add a comment |
add a comment |
$begingroup$
This can also be solved using recursion. The function cumProd (cumulative product) can be defined as:
list = Range[10];
cumProd[n_] := cumProd[n - 1]*list[[n]];
cumProd[1] = list[[1]];
To use:
cumProd[6]
720
gives the 6th "level" of the product. Of course, list can be any set of numbers. Applying this to the whole list:
cumProd/@Range[Length[list]]
{1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800}
$endgroup$
add a comment |
$begingroup$
This can also be solved using recursion. The function cumProd (cumulative product) can be defined as:
list = Range[10];
cumProd[n_] := cumProd[n - 1]*list[[n]];
cumProd[1] = list[[1]];
To use:
cumProd[6]
720
gives the 6th "level" of the product. Of course, list can be any set of numbers. Applying this to the whole list:
cumProd/@Range[Length[list]]
{1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800}
$endgroup$
add a comment |
$begingroup$
This can also be solved using recursion. The function cumProd (cumulative product) can be defined as:
list = Range[10];
cumProd[n_] := cumProd[n - 1]*list[[n]];
cumProd[1] = list[[1]];
To use:
cumProd[6]
720
gives the 6th "level" of the product. Of course, list can be any set of numbers. Applying this to the whole list:
cumProd/@Range[Length[list]]
{1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800}
$endgroup$
This can also be solved using recursion. The function cumProd (cumulative product) can be defined as:
list = Range[10];
cumProd[n_] := cumProd[n - 1]*list[[n]];
cumProd[1] = list[[1]];
To use:
cumProd[6]
720
gives the 6th "level" of the product. Of course, list can be any set of numbers. Applying this to the whole list:
cumProd/@Range[Length[list]]
{1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800}
answered 1 hour ago
bill sbill s
53.5k376152
53.5k376152
add a comment |
add a comment |
$begingroup$
here is your level function
level[x_] := Times @@ l[[;; x + 1]];
level[1]
level[2]
6
24
$endgroup$
add a comment |
$begingroup$
here is your level function
level[x_] := Times @@ l[[;; x + 1]];
level[1]
level[2]
6
24
$endgroup$
add a comment |
$begingroup$
here is your level function
level[x_] := Times @@ l[[;; x + 1]];
level[1]
level[2]
6
24
$endgroup$
here is your level function
level[x_] := Times @@ l[[;; x + 1]];
level[1]
level[2]
6
24
answered 3 hours ago
J42161217J42161217
3,792321
3,792321
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
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%2f191937%2fmultiplying-elements-of-a-list%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