本文整理汇总了Java中org.nd4j.linalg.api.ndarray.INDArray.length方法的典型用法代码示例。如果您正苦于以下问题:Java INDArray.length方法的具体用法?Java INDArray.length怎么用?Java INDArray.length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.nd4j.linalg.api.ndarray.INDArray
的用法示例。
在下文中一共展示了INDArray.length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTopN
import org.nd4j.linalg.api.ndarray.INDArray; //导入方法依赖的package包/类
/**
* Get top N elements
*
* @param vec the vec to extract the top elements from
* @param N the number of elements to extract
* @return the indices and the sorted top N elements
*/
private List<Double> getTopN(INDArray vec, int N) {
BasicModelUtils.ArrayComparator comparator = new BasicModelUtils.ArrayComparator();
PriorityQueue<Double[]> queue = new PriorityQueue<>(vec.rows(), comparator);
for (int j = 0; j < vec.length(); j++) {
final Double[] pair = new Double[] {vec.getDouble(j), (double) j};
if (queue.size() < N) {
queue.add(pair);
} else {
Double[] head = queue.peek();
if (comparator.compare(pair, head) > 0) {
queue.poll();
queue.add(pair);
}
}
}
List<Double> lowToHighSimLst = new ArrayList<>();
while (!queue.isEmpty()) {
double ind = queue.poll()[1];
lowToHighSimLst.add(ind);
}
return Lists.reverse(lowToHighSimLst);
}
示例2: check
import org.nd4j.linalg.api.ndarray.INDArray; //导入方法依赖的package包/类
private void check(BufferedImage image) throws Exception
{
ImageIO.write(image, "png", new File("tmp.png")); //saves the image to the tmp.png file
ImageRecordReader reader = new ImageRecordReader(150, 150, 3);
reader.initialize(new FileSplit(new File("tmp.png"))); //reads the tmp.png file
DataSetIterator dataIter = new RecordReaderDataSetIterator(reader, 1);
while (dataIter.hasNext())
{
//Normalize the data from the file
DataNormalization normalization = new NormalizerMinMaxScaler();
DataSet set = dataIter.next();
normalization.fit(set);
normalization.transform(set);
INDArray array = MainGUI.model.output(set.getFeatures(), false); //send the data to the model and get the results
//Process the results and print them in an understandable format (percentage scores)
String txt = "";
DecimalFormat df = new DecimalFormat("#.00");
for (int i = 0; i < array.length(); i++)
{
txt += MainGUI.labels.get(i) + ": " + (array.getDouble(i)*100 < 1 ? "0" : "") + df.format((array.getDouble(i)*100)) + "%\n";
}
probabilityArea.setText(txt);
}
reader.close();
}