本文整理了Java中org.nd4j.linalg.factory.Nd4j.concat()
方法的一些代码示例,展示了Nd4j.concat()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Nd4j.concat()
方法的具体详情如下:
包路径:org.nd4j.linalg.factory.Nd4j
类名称:Nd4j
方法名:concat
[英]Concatneate ndarrays along a dimension
[中]沿着一个维度连续排列
代码示例来源:origin: deeplearning4j/nd4j
/**
* Concatenates two matrices horizontally.
* Matrices must have identical
* numbers of rows.
*
* @param arrs
*/
public INDArray hstack(INDArray... arrs) {
return Nd4j.concat(1, arrs);
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Concatenates two matrices vertically. Matrices must have identical
* numbers of columns.
*
* @param arrs
*/
@Override
public INDArray vstack(final INDArray... arrs) {
return Nd4j.concat(0, arrs);
}
代码示例来源:origin: deeplearning4j/dl4j-examples
static INDArray append(INDArray arr1, INDArray values, int dimension) {
if(dimension == -1) {
return Nd4j.toFlattened(arr1, values);
} else {
return Nd4j.concat(dimension, arr1, values);
}
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Get a view of the underlying array
* relative to the size of the actual array.
* (Sometimes there are overflows in the internals
* but you want to use the internal INDArray for computing something
* directly, this gives you the relevant subset that reflects the content of the list)
* @return the view of the underlying ndarray relative to the collection's real size
*/
public INDArray array() {
List<INDArray> retList = new ArrayList<>(list.size());
for(X x : list) {
retList.add(x.array());
}
return Nd4j.concat(0,retList.toArray(new INDArray[retList.size()]));
}
代码示例来源:origin: deeplearning4j/dl4j-examples
System.out.println(ones);
INDArray combined = Nd4j.concat(0,zeros,ones);
INDArray combined2 = Nd4j.concat(1,zeros,ones);
代码示例来源:origin: deeplearning4j/nd4j
return Nd4j.concat(0,resultList.toArray(new INDArray[resultList.size()]));
代码示例来源:origin: deeplearning4j/nd4j
/**
* Append the given
* array with the specified value size
* along a particular axis
* @param arr the array to append to
* @param padAmount the pad amount of the array to be returned
* @param val the value to append
* @param axis the axis to append to
* @return the newly created array
*/
public static INDArray append(INDArray arr, int padAmount, double val, int axis) {
if (padAmount == 0)
return arr;
long[] paShape = ArrayUtil.copy(arr.shape());
if (axis < 0)
axis = axis + arr.shape().length;
paShape[axis] = padAmount;
INDArray concatArray = Nd4j.valueArrayOf(paShape, val);
return Nd4j.concat(axis, arr, concatArray);
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Append the given
* array with the specified value size
* along a particular axis
* @param arr the array to append to
* @param padAmount the pad amount of the array to be returned
* @param val the value to append
* @param axis the axis to append to
* @return the newly created array
*/
public static INDArray prepend(INDArray arr, int padAmount, double val, int axis) {
if (padAmount == 0)
return arr;
long[] paShape = ArrayUtil.copy(arr.shape());
if (axis < 0)
axis = axis + arr.shape().length;
paShape[axis] = padAmount;
INDArray concatArr = Nd4j.valueArrayOf(paShape, val);
return Nd4j.concat(axis, concatArr, arr);
}
代码示例来源:origin: deeplearning4j/nd4j
return Nd4j.concat(0,arrList.toArray(new INDArray[arrList.size()]));
代码示例来源:origin: deeplearning4j/nd4j
return Nd4j.concat(0,arrList.toArray(new INDArray[arrList.size()]));
代码示例来源:origin: deeplearning4j/dl4j-examples
static INDArray insert(INDArray arr1, int index, INDArray values, int dimension) {
if(dimension == -1) {
INDArray flat1 = Nd4j.toFlattened(arr1);
INDArray flatValues = Nd4j.toFlattened(values);
INDArray firstSlice = flat1.get(NDArrayIndex.interval(0, index));
INDArray secondSlice = flat1.get(NDArrayIndex.interval(index, flat1.length()));
return Nd4j.toFlattened(firstSlice, flatValues, secondSlice);
} else {
INDArray firstSlice = arr1.get(createIntervalOnDimension(dimension, false,
0, index));
INDArray secondSlice = arr1.get(createIntervalOnDimension(dimension, false,
index, arr1.shape()[dimension]));
return Nd4j.concat(dimension, firstSlice, values, secondSlice);
}
}
代码示例来源:origin: deeplearning4j/dl4j-examples
static INDArray delete(int dimension, INDArray arr1, int... interval) {
int length = interval.length;
int lastIntervalValue = interval[length - 1];
if(dimension == -1) {
INDArray array1 = arr1.get(NDArrayIndex.interval(0, interval[0]));
if(lastIntervalValue == arr1.length() - 1) {
return Nd4j.toFlattened(array1);
} else {
INDArray array2 = arr1.get(NDArrayIndex.interval(lastIntervalValue + 1,
arr1.length()));
return Nd4j.toFlattened(array1, array2);
}
} else {
INDArray array1 = arr1.get(createIntervalOnDimension(dimension, false, 0, interval[0]));
if(lastIntervalValue == arr1.shape()[dimension] - 1) {
return array1;
} else {
INDArray array2 = arr1.get(createIntervalOnDimension(dimension, false,
lastIntervalValue + 1,
arr1.shape()[dimension]));
return Nd4j.concat(dimension, array1, array2);
}
}
}
代码示例来源:origin: deeplearning4j/dl4j-examples
INDArray concatenatedAxisZero = Nd4j.concat(0, Nd4j.create(3, 2), Nd4j.create(5, 2));
print("Concatenated arrays on dimension zero", concatenatedAxisZero);
INDArray concatenatedAxisOne = Nd4j.concat(1, Nd4j.create(3, 2), Nd4j.create(3, 5));
print("Concatenated arrays on dimension 1", concatenatedAxisOne);
代码示例来源:origin: org.nd4j/nd4j-api
/**
* Concatenates two matrices horizontally.
* Matrices must have identical
* numbers of rows.
*
* @param arrs
*/
public INDArray hstack(INDArray... arrs) {
return Nd4j.concat(1, arrs);
}
代码示例来源:origin: org.nd4j/nd4j-api
/**
* Concatenates two matrices vertically. Matrices must have identical
* numbers of columns.
*
* @param arrs
*/
@Override
public INDArray vstack(final INDArray... arrs) {
return Nd4j.concat(0, arrs);
}
代码示例来源:origin: neo4j-graph-analytics/ml-models
private void diffuse(List<Pruning.Feature> featuresList) {
INDArray ndDiffused = Nd4j.create(embedding.shape());
Nd4j.copy(embedding, ndDiffused);
featuresList.addAll(featuresList);
features = featuresList.toArray(new Pruning.Feature[0]);
for (int i = features.length / 2; i < features.length; i++) {
features[i] = new Pruning.Feature("diffuse", features[i]);
}
for (int diffIteration = 0; diffIteration < diffusionIterations; diffIteration++) {
INDArray ndDiffusedTemp = Nd4j.create(embedding.shape());
nodeQueue.set(0);
final ArrayList<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < concurrency; i++) {
futures.add(executorService.submit(new DiffusionTask(ndDiffused, ndDiffusedTemp)));
}
ParallelUtil.awaitTermination(futures);
ndDiffused = ndDiffusedTemp;
}
embedding = Nd4j.concat(1, embedding, ndDiffused);
}
代码示例来源:origin: org.nd4j/nd4j-api
/**
* Append the given
* array with the specified value size
* along a particular axis
* @param arr the array to append to
* @param padAmount the pad amount of the array to be returned
* @param val the value to append
* @param axis the axis to append to
* @return the newly created array
*/
public static INDArray append(INDArray arr, int padAmount, double val, int axis) {
if (padAmount == 0)
return arr;
int[] paShape = ArrayUtil.copy(arr.shape());
if (axis < 0)
axis = axis + arr.shape().length;
paShape[axis] = padAmount;
INDArray concatArray = Nd4j.valueArrayOf(paShape, val);
return Nd4j.concat(axis, arr, concatArray);
}
代码示例来源:origin: org.nd4j/nd4j-api
/**
* Append the given
* array with the specified value size
* along a particular axis
* @param arr the array to append to
* @param padAmount the pad amount of the array to be returned
* @param val the value to append
* @param axis the axis to append to
* @return the newly created array
*/
public static INDArray prepend(INDArray arr, int padAmount, double val, int axis) {
if (padAmount == 0)
return arr;
int[] paShape = ArrayUtil.copy(arr.shape());
if (axis < 0)
axis = axis + arr.shape().length;
paShape[axis] = padAmount;
INDArray concatArr = Nd4j.valueArrayOf(paShape, val);
return Nd4j.concat(axis, concatArr, arr);
}
代码示例来源:origin: improbable-research/keanu
/**
* @param dimension the dimension along which the tensors will be joined
* @param toConcat an array of IntegerTensor
* @return an IntegerTensor with toConcat joined along existing dimension
* <p>
* e.g. A, B, C = IntegerTensor.ones(4, 2)
* <p>
* IntegerTensor.concat(0, A, B, C) gives IntegerTensor.ones(12, 2)
*/
static IntegerTensor concat(int dimension, IntegerTensor... toConcat) {
INDArray[] concatAsINDArray = new INDArray[toConcat.length];
for (int i = 0; i < toConcat.length; i++) {
concatAsINDArray[i] = Nd4jIntegerTensor.unsafeGetNd4J(toConcat[i]).dup();
if (concatAsINDArray[i].shape().length == 0) {
concatAsINDArray[i] = concatAsINDArray[i].reshape(1);
}
}
INDArray concat = Nd4j.concat(dimension, concatAsINDArray);
return new Nd4jIntegerTensor(concat);
}
代码示例来源:origin: improbable-research/keanu
/**
* @param dimension the dimension along which the tensors will be joined
* @param toConcat an array of DoubleTensor
* @return a DoubleTensor with toConcat joined along an existing dimension
* <p>
* e.g. A, B, C = DoubleTensor.ones(4, 2)
* <p>
* DoubleTensor.concat(0, A, B, C) gives DoubleTensor.ones(12, 2)
*/
static DoubleTensor concat(int dimension, DoubleTensor... toConcat) {
INDArray[] concatAsINDArray = new INDArray[toConcat.length];
for (int i = 0; i < toConcat.length; i++) {
concatAsINDArray[i] = Nd4jDoubleTensor.unsafeGetNd4J(toConcat[i]).dup();
if (concatAsINDArray[i].shape().length == 0) {
concatAsINDArray[i] = concatAsINDArray[i].reshape(1);
}
}
INDArray concat = Nd4j.concat(dimension, concatAsINDArray);
return new Nd4jDoubleTensor(concat);
}
内容来源于网络,如有侵权,请联系作者删除!