當前位置: 首頁>>代碼示例>>Java>>正文


Java INDArray.shape方法代碼示例

本文整理匯總了Java中org.nd4j.linalg.api.ndarray.INDArray.shape方法的典型用法代碼示例。如果您正苦於以下問題:Java INDArray.shape方法的具體用法?Java INDArray.shape怎麽用?Java INDArray.shape使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.nd4j.linalg.api.ndarray.INDArray的用法示例。


在下文中一共展示了INDArray.shape方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: clipMatrix

import org.nd4j.linalg.api.ndarray.INDArray; //導入方法依賴的package包/類
/**
 * Clip the values within a matrix to -5 to 5 range, to avoid exploding gradients
 * @param matrix
 * @return
 */
private static INDArray clipMatrix(INDArray matrix) {
    NdIndexIterator iter = new NdIndexIterator(matrix.shape());
    while (iter.hasNext()) {
        int[] nextIndex = iter.next();
        double nextVal = matrix.getDouble(nextIndex);
        if (nextVal < -5) {
            nextVal = -5;
        }
        if (nextVal > 5) {
            nextVal = 5;
        }
        matrix.putScalar(nextIndex, nextVal);
    }
    return matrix;
}
 
開發者ID:guilherme-pombo,項目名稱:JavaRNN,代碼行數:21,代碼來源:CharRNN.java

示例2: updateData

import org.nd4j.linalg.api.ndarray.INDArray; //導入方法依賴的package包/類
public static DefaultData updateData(DefaultData oldData, INDArray newData){
		DefaultData.Builder dataBuilder = DefaultData.newBuilder();
		
		dataBuilder.addAllNames(oldData.getNamesList());
		
//		int index=0;
//		for (Iterator<String> i = oldData.getFeaturesList().iterator(); i.hasNext();){
//			dataBuilder.setFeatures(index, i.next());
//			index++;
//		}
		
		if (oldData.getDataOneofCase() == DataOneofCase.TENSOR){
			Tensor.Builder tBuilder = Tensor.newBuilder();
			List<Integer> shapeList = Arrays.stream(newData.shape()).boxed().collect(Collectors.toList());
			tBuilder.addAllShape(shapeList);
			
			for (int i=0; i<shapeList.get(0); ++i){
				for (int j=0; j<shapeList.get(1); ++j){
					tBuilder.addValues(newData.getDouble(i,j));
				}
			}
			dataBuilder.setTensor(tBuilder);
			return dataBuilder.build();
		}
		else if (oldData.getDataOneofCase() == DataOneofCase.NDARRAY){
			ListValue.Builder b1 = ListValue.newBuilder();
			for (int i = 0; i < newData.shape()[0]; ++i) {
				ListValue.Builder b2 = ListValue.newBuilder();
				for (int j = 0; j < newData.shape()[1]; j++){
					b2.addValues(Value.newBuilder().setNumberValue(newData.getDouble(i,j)));
				}
				b1.addValues(Value.newBuilder().setListValue(b2.build()));
			}
			dataBuilder.setNdarray(b1.build());
			return dataBuilder.build();
		}
		return null;
		
	}
 
開發者ID:SeldonIO,項目名稱:seldon-core,代碼行數:40,代碼來源:PredictorUtils.java


注:本文中的org.nd4j.linalg.api.ndarray.INDArray.shape方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。