Nd4J:获取存在值的索引

Nd4J: get index where a value exists

如何获取存在特定值的索引。在 numpy 中:

import numpy as np
myArr = np.array()
index = np.where(myArr == someValue)
// Output: an index value consisting rows and cols will be given

在ND4J中,我已经到了这里,但我不知道在条件参数中放什么:

INDArray index = myArr.getWhere(someValue, condition=??);

换句话说,如何在ND4J中查找INDArray中的元素?

只需使用Conditions.equals

首先导入Conditions

import org.nd4j.linalg.indexing.conditions.Conditions;

然后:

myArr.getWhere(someValue, Conditions.equals(1));

BooleanIndexing.firstIndex(INDArray, Condition) 就是我认为的你要找的。