Java Code Examples for org.nd4j.linalg.indexing.NDArrayIndex#newAxis()

The following examples show how to use org.nd4j.linalg.indexing.NDArrayIndex#newAxis() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndexShapeTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testNewAxis() {
    //normal prepend
    int[] prependAssertion = {1, 1, 1, 1, 2, 1, 3, 4, 5, 1};
    INDArrayIndex[] prependTest = {NDArrayIndex.newAxis(), NDArrayIndex.newAxis(), NDArrayIndex.all(),
                    NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.all(),
                    NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.all(),

    };

    assertArrayEquals(prependAssertion, Indices.shape(shape, prependTest));

    //test setting for particular indexes.
    //when an all is encountered before a new axis,
    //it is assumed that new axis must occur at the destination
    //where the new axis was specified
    int[] addToMiddle = {1, 1, 2, 1, 1, 1, 3, 4, 5, 1};
    INDArrayIndex[] setInMiddleTest = {NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.all(),
                    NDArrayIndex.newAxis(), NDArrayIndex.newAxis(), NDArrayIndex.all(), NDArrayIndex.all(),
                    NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.all(),};
    assertArrayEquals(addToMiddle, Indices.shape(shape, setInMiddleTest));

    //test prepending AND adding to middle
    int[] prependAndAddToMiddleAssertion = {1, 1, 1, 1, 2, 1, 1, 1, 3, 4, 5, 1};

    INDArrayIndex[] prependAndMiddle = {NDArrayIndex.newAxis(), NDArrayIndex.newAxis(), NDArrayIndex.all(),
                    NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.newAxis(), NDArrayIndex.newAxis(),
                    NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.all(),
                    NDArrayIndex.all(),};
    assertArrayEquals(prependAndAddToMiddleAssertion, Indices.shape(shape, prependAndMiddle));

}
 
Example 2
Source File: IndexShapeTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testNewAxis() {
    //normal prepend
    int[] prependAssertion = {1, 1, 1, 1, 2, 1, 3, 4, 5, 1};
    INDArrayIndex[] prependTest = {NDArrayIndex.newAxis(), NDArrayIndex.newAxis(), NDArrayIndex.all(),
                    NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.all(),
                    NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.all(),

    };

    assertArrayEquals(prependAssertion, Indices.shape(shape, prependTest));

    //test setting for particular indexes.
    //when an all is encountered before a new axis,
    //it is assumed that new axis must occur at the destination
    //where the new axis was specified
    int[] addToMiddle = {1, 1, 2, 1, 1, 1, 3, 4, 5, 1};
    INDArrayIndex[] setInMiddleTest = {NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.all(),
                    NDArrayIndex.newAxis(), NDArrayIndex.newAxis(), NDArrayIndex.all(), NDArrayIndex.all(),
                    NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.all(),};
    assertArrayEquals(addToMiddle, Indices.shape(shape, setInMiddleTest));

    //test prepending AND adding to middle
    int[] prependAndAddToMiddleAssertion = {1, 1, 1, 1, 2, 1, 1, 1, 3, 4, 5, 1};

    INDArrayIndex[] prependAndMiddle = {NDArrayIndex.newAxis(), NDArrayIndex.newAxis(), NDArrayIndex.all(),
                    NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.newAxis(), NDArrayIndex.newAxis(),
                    NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.all(),
                    NDArrayIndex.all(),};
    assertArrayEquals(prependAndAddToMiddleAssertion, Indices.shape(shape, prependAndMiddle));

}