Search in sources :

Example 1 with FirstIndex

use of org.nd4j.linalg.api.ops.impl.indexaccum.FirstIndex in project nd4j by deeplearning4j.

the class BooleanIndexing method firstIndex.

/**
 * This method returns first index matching given condition
 *
 * PLEASE NOTE: This method will return -1 value if condition wasn't met
 *
 * @param array
 * @param condition
 * @return
 */
public static INDArray firstIndex(INDArray array, Condition condition) {
    if (!(condition instanceof BaseCondition))
        throw new UnsupportedOperationException("Only static Conditions are supported");
    FirstIndex idx = new FirstIndex(array, condition);
    Nd4j.getExecutioner().exec(idx);
    return Nd4j.scalar((double) idx.getFinalResult());
}
Also used : FirstIndex(org.nd4j.linalg.api.ops.impl.indexaccum.FirstIndex) BaseCondition(org.nd4j.linalg.indexing.conditions.BaseCondition)

Aggregations

FirstIndex (org.nd4j.linalg.api.ops.impl.indexaccum.FirstIndex)1 BaseCondition (org.nd4j.linalg.indexing.conditions.BaseCondition)1