javand4j

Nd4j permute does not permute - what have I done wrong?


i am trying to permute an array as described in the documentation (actual a link to mathworks).

My code, however does not reproduce the results. Actually, it seems like my code does nothing:

INDArray foobar = Nd4j.linspace(0, 2, 3);
System.out.println("foobar = " + foobar);
System.out.println("foobar.permute(2, 1, 0) = " + foobar.permute(2, 1, 0));

Output is the same for foobar and foobar.permute. Where did I mess up?

Optional: Any information on how permute work (syntax-wise) with higher dimensions like 2d or 3d matrices would be appreciated.


Solution

  • According to the documentation you linked to, permute method is used to permute the dimensions of a multi-dimensional array. Nd4j.linspace creates a vector (a 1-dimensional array). Since there is only one dimension, there is no other dimension to permute it with. The example on Mathworks on the other hand, creates a 3-dimentional array and permutes the 1st and 3rd dimension.

    It sounds like your intention was to permute the individual elements of an array (not entire dimensions). I haven't seen a method for that in Nd4j.