3
$\begingroup$

I have some problems with the built-in function Differences. I do not understand how its behaviour comes about under the following circumstances:

vec = {a, b, c, d, e, f, g, h};
vec2 = ConstantArray[1, 10];

Differences[#, 1, 0]^2 & /@ {vec, vec2}

gives me

{{0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 1}}

as an output. What is the reason for the 1 in the last entry of the second list? Shouldn't it be 0 as well?

$\endgroup$
8
  • 1
    $\begingroup$ Win10 V11.2 returns only 0s. $\endgroup$
    – Kuba
    Commented Feb 12, 2018 at 10:38
  • $\begingroup$ Good to know. I use Linux V10.0.1. So it is supposed to be a bug I guess? $\endgroup$
    – NeverMind
    Commented Feb 12, 2018 at 11:04
  • $\begingroup$ Win 7 MMA 11.2 also returns only 0s $\endgroup$ Commented Feb 12, 2018 at 11:46
  • $\begingroup$ Version 11.0.1 on macos 10.13.3 also returns zeroes only. Have you tried to restart the kernel before running the code? $\endgroup$ Commented Feb 12, 2018 at 13:22
  • $\begingroup$ What are you trying to achieve with this code? The zero in the third slot of Differences indicates how many steps apart in the array elements should be so not entirely sure 0 makes sense here in the first place $\endgroup$
    – gpap
    Commented Feb 12, 2018 at 13:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.