How to get sum of eath two elements with the vector functions? I want the same result as:
{x+y}':[1 2 3 2 1]
Why this approach gives something different than first one?
sum':[1 2 3 2 1]
How to get sum of eath two elements with the vector functions? I want the same result as:
{x+y}':[1 2 3 2 1]
Why this approach gives something different than first one?
sum':[1 2 3 2 1]
Copyright © 2021 Jogjafile Inc.
sumis not the same as{x+y}.sumhas rank 1 meaning it takes one input and sums the elements of that input.It can sum an atom:
a uniform list
or a list of lists
{x+y}is rank 2 meaning it requires two inputs.Giving it an atom, a single list, or a list of lists leads to projections
Since each-prior (
':) creates binary pairs from the input and attempts to apply a rank 2 function, it works as intended on your rank 2 function{x+y}.But since
sumis not rank 2 the each-prior doesn't generate pairs in the same way, it's equivalent to doingYou could force it to be rank 2:
but this gives a different result since
sumignores nulls while+doesn't.Finally, an alternative way to achieve this using sum (and without using each-prior) is to shift the vector using
prevand then sum