1

What determines the shape of the result of a vector mapping (V M)? I had thought it was directly based on the shape of the input, but have a look at this.

k f factors an integer, returning a vector of its prime factors. Given a vector of n integers,

[27 31 33]

V M k f will factor all of them, yielding

[[3, 3, 3], [31], [3, 11]]

which is what I'd expect. But if all of them are primes, for example

[31, 37, 41]

then the output of V M k f is

[ [ 31 ]
  [ 37 ]
  [ 41 ] ]

The shape (H v l) of the first result is [3]; the shape of the second result is [3, 1]. Why?

  • 1
    Both cases return a vector of vectors. In the second case, as all vectors are length 1, it is equivalent to a matrix, thus [3,1]. Similarly, factoring a vector of 3 squares [9,25,49] yields a matrix of size [3,2] because all results are vectors of size 2. – Juancho Nov 19 '15 at 17:46
  • Okay, that makes sense. I was thrown by the difference in how the result is displayed, plus the inability to do certain further mappings in the second case. – Sue D. Nymme Nov 19 '15 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.