本文整理匯總了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;
}
示例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;
}