本文整理了Java中org.nd4j.linalg.factory.Nd4j.vstack()
方法的一些代码示例,展示了Nd4j.vstack()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Nd4j.vstack()
方法的具体详情如下:
包路径:org.nd4j.linalg.factory.Nd4j
类名称:Nd4j
方法名:vstack
[英]Concatenates two matrices vertically. Matrices must have identical numbers of columns.
[中]垂直连接两个矩阵。矩阵的列数必须相同。
代码示例来源:origin: deeplearning4j/dl4j-examples
INDArray vstack = Nd4j.vstack(ones,zeros);
System.out.println("### VSTACK ####");
System.out.println(vstack);
代码示例来源:origin: deeplearning4j/nd4j
/**
* This method stacks vertically examples with the same shape, increasing result dimensionality. I.e. if you provide bunch of 3D tensors, output will be 4D tensor. Alignment is always applied to axis 0.
*
* @return
*/
public static INDArray pile(INDArray... arrays) {
// if we have vectors as input, it's just vstack use case
if (arrays[0].isRowVector() && arrays[0].rank() == 2) {
return Nd4j.vstack(arrays);
}
long[] shape = arrays[0].shape();
long[] newShape = ArrayUtils.add(shape, 0, 1);
boolean shouldReshape = true;
if (arrays[0].size(0) == 1)
shouldReshape = false;
List<INDArray> reshaped = new ArrayList<>();
for(INDArray array: arrays) {
if (!shouldReshape)
reshaped.add(array);
else
reshaped.add(array.reshape(array.ordering(), newShape));
}
return Nd4j.vstack(reshaped);
}
代码示例来源:origin: deeplearning4j/dl4j-examples
INDArray rowVector2 = Nd4j.create(new double[]{4,5,6});
INDArray vStack = Nd4j.vstack(rowVector1, rowVector2); //Vertical stack: [1,3]+[1,3] to [2,3]
代码示例来源:origin: org.nd4j/nd4j-api
/**
* This method stacks vertically examples with the same shape, increasing result dimensionality. I.e. if you provide bunch of 3D tensors, output will be 4D tensor. Alignment is always applied to axis 0.
*
* @return
*/
public static INDArray pile(INDArray... arrays) {
// if we have vectors as input, it's just vstack use case
if (arrays[0].isRowVector()) {
return Nd4j.vstack(arrays);
}
int[] shape = arrays[0].shape();
int[] newShape = ArrayUtils.add(shape, 0, 1);
boolean shouldReshape = true;
if (arrays[0].size(0) == 1)
shouldReshape = false;
List<INDArray> reshaped = new ArrayList<>();
for(INDArray array: arrays) {
if (!shouldReshape)
reshaped.add(array);
else
reshaped.add(array.reshape(array.ordering(), newShape));
}
return Nd4j.vstack(reshaped);
}
代码示例来源:origin: org.deeplearning4j/nearestneighbor-core
Nd4j.getWorkspaceManager().getAndActivateWorkspace(workspaceConfiguration, "VPTREE_WORSKPACE");
INDArray items = Nd4j.vstack(points);
int randomPoint = MathUtils.randomNumberBetween(0, items.rows() - 1, Nd4j.getRandom());
代码示例来源:origin: org.deeplearning4j/deeplearning4j-nn
/**
* Label the probabilities of the input
*
* @param iterator test data to evaluate
* @return a vector of probabilities
* given each label.
* <p>
* This is typically of the form:
* [0.5, 0.5] or some other probability distribution summing to one
*/
public INDArray output(DataSetIterator iterator, boolean train) {
List<INDArray> outList = new ArrayList<>();
while (iterator.hasNext()) {
DataSet next = iterator.next();
if (next.getFeatureMatrix() == null || next.getLabels() == null)
break;
INDArray features = next.getFeatures();
if (next.hasMaskArrays()) {
INDArray fMask = next.getFeaturesMaskArray();
INDArray lMask = next.getLabelsMaskArray();
outList.add(this.output(features, train, fMask, lMask));
} else {
outList.add(output(features, train));
}
}
return Nd4j.vstack(outList.toArray(new INDArray[0]));
}
代码示例来源:origin: neo4j-graph-analytics/ml-models
@Override
public INDArray ndOp(INDArray features, INDArray adjacencyMatrix) {
INDArray[] had = new INDArray[adjacencyMatrix.columns()];
for (int column = 0; column < adjacencyMatrix.columns(); column++) {
int finalColumn = column;
int[] indexes = IntStream.range(0, adjacencyMatrix.rows())
.filter(r -> adjacencyMatrix.getDouble(finalColumn, r) != 0)
.toArray();
if (indexes.length > 0) {
had[column] = Nd4j.ones(features.columns());
for (int index : indexes) {
had[column].muli(features.getRow(index));
}
} else {
INDArray zeros = Nd4j.zeros(features.columns());
had[column] = zeros;
}
}
return Nd4j.vstack(had);
}
代码示例来源:origin: de.datexis/texoo-core
.build();
INDArray syn = Nd4j.vstack(arrays);
代码示例来源:origin: neo4j-graph-analytics/ml-models
@Override
public INDArray ndOp(INDArray features, INDArray adjacencyMatrix) {
double sigma = 16;
INDArray[] sumsOfSquareDiffs = new INDArray[adjacencyMatrix.rows()];
for (int node = 0; node < adjacencyMatrix.rows(); node++) {
INDArray column = adjacencyMatrix.getColumn(node);
INDArray repeat = features.getRow(node).repeat(0, features.rows()).muliColumnVector(column);
INDArray sub = repeat.sub(features.mulColumnVector(column));
sumsOfSquareDiffs[node] = Transforms.pow(sub, 2).sum(0);
}
INDArray sumOfSquareDiffs = Nd4j.vstack(sumsOfSquareDiffs).muli(-(1d / Math.pow(sigma, 2)));
return Transforms.exp(sumOfSquareDiffs);
}
代码示例来源:origin: org.deeplearning4j/deeplearning4j-utility-iterators
INDArray features = null;
if (ndLabels != null) {
labels = Nd4j.vstack(ndLabels);
features = Nd4j.vstack(ndFeatures);
} else if (fLabels != null) {
labels = Nd4j.create(fLabels);
代码示例来源:origin: org.deeplearning4j/deeplearning4j-nn
INDArray features = null;
if (ndLabels != null) {
labels = Nd4j.vstack(ndLabels);
features = Nd4j.vstack(ndFeatures);
} else if (fLabels != null) {
labels = Nd4j.create(fLabels);
代码示例来源:origin: org.deeplearning4j/deeplearning4j-nn
@Override
public Pair<INDArray, MaskState> feedForwardMaskArrays(INDArray[] maskArrays, MaskState currentMaskState,
int minibatchSize) {
//Cases here: no mask arrays, or all mask arrays - all of the same size
if (maskArrays == null) {
return new Pair<>(null, currentMaskState);
}
// stacking along dimension 0
//Given masks are all either 1d (column vector) or 2d (examples, timeSeriesLength) we can just vStack the masks
//However: variable length TS might have different length masks...
boolean allSameLength = true;
int size1_ex0 = maskArrays[0].size(1);
int maxLength = size1_ex0;
for (int i = 1; i < maskArrays.length; i++) {
allSameLength &= (size1_ex0 == maskArrays[i].size(1));
maxLength = Math.max(maxLength, maskArrays[i].size(1));
}
if (allSameLength) {
return new Pair<>(Nd4j.vstack(maskArrays), currentMaskState);
} else {
int numExamples = maskArrays[0].size(0);
INDArray outMask = Nd4j.create(maskArrays.length * numExamples, maxLength);
for (int i = 0; i < maskArrays.length; i++) {
outMask.put(new INDArrayIndex[] {NDArrayIndex.interval(i * numExamples, (i + 1) * numExamples),
NDArrayIndex.interval(0, maskArrays[i].size(1))}, maskArrays[i]);
}
return new Pair<>(outMask, currentMaskState);
}
}
代码示例来源:origin: neo4j-graph-analytics/ml-models
@Override
public INDArray ndOp(INDArray features, INDArray adjacencyMatrix) {
INDArray[] norms = new INDArray[adjacencyMatrix.rows()];
for (int node = 0; node < adjacencyMatrix.rows(); node++) {
INDArray nodeFeatures = features.getRow(node);
INDArray adjs = adjacencyMatrix.transpose().getColumn(node).repeat(1, features.columns());
INDArray repeat = nodeFeatures.repeat(0, features.rows()).mul(adjs);
INDArray sub = repeat.sub(features.mul(adjs));
INDArray norm = sub.norm1(0);
norms[node] = norm;
}
return Nd4j.vstack(norms);
}
内容来源于网络,如有侵权,请联系作者删除!