No output arrays were provided and calculateOutputShape failed to execute INDArray.getWhere()

I am trying the following code for boolean indexing:

    INDArray scalarValues = Nd4j.createFromArray(new int[] {1, 2, 3, 4, 5});
    INDArray values = Nd4j.ones(DataType.INT32, 5);
    INDArray result = scalarValues.getWhere(values, Conditions.greaterThan(0));

However, my I get the following errors:

Op [choose] failed check for input [0], DataType: [INT32]
Failed to calculate output shapes for op choose

The following exception gets thrown as well:
org.nd4j.linalg.exception.ND4JIllegalStateException: Op name choose - no output arrays were provided and calculateOutputShape failed to execute

What am I missing here? In this case, I was expecting to get an empty NDArray back. I had similar errors when trying to use BooleanIndexing.chooseFrom. The documentation there is not particular clear on the semantics of the input parameters, in particular how Condition is supposed to work.

2 Likes