org.nd4j.linalg.factory.Nd4j.concat()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(206)

本文整理了Java中org.nd4j.linalg.factory.Nd4j.concat()方法的一些代码示例,展示了Nd4j.concat()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Nd4j.concat()方法的具体详情如下:
包路径:org.nd4j.linalg.factory.Nd4j
类名称:Nd4j
方法名:concat

Nd4j.concat介绍

[英]Concatneate ndarrays along a dimension
[中]沿着一个维度连续排列

代码示例

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Concatenates two matrices horizontally.
  3. * Matrices must have identical
  4. * numbers of rows.
  5. *
  6. * @param arrs
  7. */
  8. public INDArray hstack(INDArray... arrs) {
  9. return Nd4j.concat(1, arrs);
  10. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Concatenates two matrices vertically. Matrices must have identical
  3. * numbers of columns.
  4. *
  5. * @param arrs
  6. */
  7. @Override
  8. public INDArray vstack(final INDArray... arrs) {
  9. return Nd4j.concat(0, arrs);
  10. }

代码示例来源:origin: deeplearning4j/dl4j-examples

  1. static INDArray append(INDArray arr1, INDArray values, int dimension) {
  2. if(dimension == -1) {
  3. return Nd4j.toFlattened(arr1, values);
  4. } else {
  5. return Nd4j.concat(dimension, arr1, values);
  6. }
  7. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Get a view of the underlying array
  3. * relative to the size of the actual array.
  4. * (Sometimes there are overflows in the internals
  5. * but you want to use the internal INDArray for computing something
  6. * directly, this gives you the relevant subset that reflects the content of the list)
  7. * @return the view of the underlying ndarray relative to the collection's real size
  8. */
  9. public INDArray array() {
  10. List<INDArray> retList = new ArrayList<>(list.size());
  11. for(X x : list) {
  12. retList.add(x.array());
  13. }
  14. return Nd4j.concat(0,retList.toArray(new INDArray[retList.size()]));
  15. }

代码示例来源:origin: deeplearning4j/dl4j-examples

  1. System.out.println(ones);
  2. INDArray combined = Nd4j.concat(0,zeros,ones);
  3. INDArray combined2 = Nd4j.concat(1,zeros,ones);

代码示例来源:origin: deeplearning4j/nd4j

  1. return Nd4j.concat(0,resultList.toArray(new INDArray[resultList.size()]));

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Append the given
  3. * array with the specified value size
  4. * along a particular axis
  5. * @param arr the array to append to
  6. * @param padAmount the pad amount of the array to be returned
  7. * @param val the value to append
  8. * @param axis the axis to append to
  9. * @return the newly created array
  10. */
  11. public static INDArray append(INDArray arr, int padAmount, double val, int axis) {
  12. if (padAmount == 0)
  13. return arr;
  14. long[] paShape = ArrayUtil.copy(arr.shape());
  15. if (axis < 0)
  16. axis = axis + arr.shape().length;
  17. paShape[axis] = padAmount;
  18. INDArray concatArray = Nd4j.valueArrayOf(paShape, val);
  19. return Nd4j.concat(axis, arr, concatArray);
  20. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Append the given
  3. * array with the specified value size
  4. * along a particular axis
  5. * @param arr the array to append to
  6. * @param padAmount the pad amount of the array to be returned
  7. * @param val the value to append
  8. * @param axis the axis to append to
  9. * @return the newly created array
  10. */
  11. public static INDArray prepend(INDArray arr, int padAmount, double val, int axis) {
  12. if (padAmount == 0)
  13. return arr;
  14. long[] paShape = ArrayUtil.copy(arr.shape());
  15. if (axis < 0)
  16. axis = axis + arr.shape().length;
  17. paShape[axis] = padAmount;
  18. INDArray concatArr = Nd4j.valueArrayOf(paShape, val);
  19. return Nd4j.concat(axis, concatArr, arr);
  20. }

代码示例来源:origin: deeplearning4j/nd4j

  1. return Nd4j.concat(0,arrList.toArray(new INDArray[arrList.size()]));

代码示例来源:origin: deeplearning4j/nd4j

  1. return Nd4j.concat(0,arrList.toArray(new INDArray[arrList.size()]));

代码示例来源:origin: deeplearning4j/dl4j-examples

  1. static INDArray insert(INDArray arr1, int index, INDArray values, int dimension) {
  2. if(dimension == -1) {
  3. INDArray flat1 = Nd4j.toFlattened(arr1);
  4. INDArray flatValues = Nd4j.toFlattened(values);
  5. INDArray firstSlice = flat1.get(NDArrayIndex.interval(0, index));
  6. INDArray secondSlice = flat1.get(NDArrayIndex.interval(index, flat1.length()));
  7. return Nd4j.toFlattened(firstSlice, flatValues, secondSlice);
  8. } else {
  9. INDArray firstSlice = arr1.get(createIntervalOnDimension(dimension, false,
  10. 0, index));
  11. INDArray secondSlice = arr1.get(createIntervalOnDimension(dimension, false,
  12. index, arr1.shape()[dimension]));
  13. return Nd4j.concat(dimension, firstSlice, values, secondSlice);
  14. }
  15. }

代码示例来源:origin: deeplearning4j/dl4j-examples

  1. static INDArray delete(int dimension, INDArray arr1, int... interval) {
  2. int length = interval.length;
  3. int lastIntervalValue = interval[length - 1];
  4. if(dimension == -1) {
  5. INDArray array1 = arr1.get(NDArrayIndex.interval(0, interval[0]));
  6. if(lastIntervalValue == arr1.length() - 1) {
  7. return Nd4j.toFlattened(array1);
  8. } else {
  9. INDArray array2 = arr1.get(NDArrayIndex.interval(lastIntervalValue + 1,
  10. arr1.length()));
  11. return Nd4j.toFlattened(array1, array2);
  12. }
  13. } else {
  14. INDArray array1 = arr1.get(createIntervalOnDimension(dimension, false, 0, interval[0]));
  15. if(lastIntervalValue == arr1.shape()[dimension] - 1) {
  16. return array1;
  17. } else {
  18. INDArray array2 = arr1.get(createIntervalOnDimension(dimension, false,
  19. lastIntervalValue + 1,
  20. arr1.shape()[dimension]));
  21. return Nd4j.concat(dimension, array1, array2);
  22. }
  23. }
  24. }

代码示例来源:origin: deeplearning4j/dl4j-examples

  1. INDArray concatenatedAxisZero = Nd4j.concat(0, Nd4j.create(3, 2), Nd4j.create(5, 2));
  2. print("Concatenated arrays on dimension zero", concatenatedAxisZero);
  3. INDArray concatenatedAxisOne = Nd4j.concat(1, Nd4j.create(3, 2), Nd4j.create(3, 5));
  4. print("Concatenated arrays on dimension 1", concatenatedAxisOne);

代码示例来源:origin: org.nd4j/nd4j-api

  1. /**
  2. * Concatenates two matrices horizontally.
  3. * Matrices must have identical
  4. * numbers of rows.
  5. *
  6. * @param arrs
  7. */
  8. public INDArray hstack(INDArray... arrs) {
  9. return Nd4j.concat(1, arrs);
  10. }

代码示例来源:origin: org.nd4j/nd4j-api

  1. /**
  2. * Concatenates two matrices vertically. Matrices must have identical
  3. * numbers of columns.
  4. *
  5. * @param arrs
  6. */
  7. @Override
  8. public INDArray vstack(final INDArray... arrs) {
  9. return Nd4j.concat(0, arrs);
  10. }

代码示例来源:origin: neo4j-graph-analytics/ml-models

  1. private void diffuse(List<Pruning.Feature> featuresList) {
  2. INDArray ndDiffused = Nd4j.create(embedding.shape());
  3. Nd4j.copy(embedding, ndDiffused);
  4. featuresList.addAll(featuresList);
  5. features = featuresList.toArray(new Pruning.Feature[0]);
  6. for (int i = features.length / 2; i < features.length; i++) {
  7. features[i] = new Pruning.Feature("diffuse", features[i]);
  8. }
  9. for (int diffIteration = 0; diffIteration < diffusionIterations; diffIteration++) {
  10. INDArray ndDiffusedTemp = Nd4j.create(embedding.shape());
  11. nodeQueue.set(0);
  12. final ArrayList<Future<?>> futures = new ArrayList<>();
  13. for (int i = 0; i < concurrency; i++) {
  14. futures.add(executorService.submit(new DiffusionTask(ndDiffused, ndDiffusedTemp)));
  15. }
  16. ParallelUtil.awaitTermination(futures);
  17. ndDiffused = ndDiffusedTemp;
  18. }
  19. embedding = Nd4j.concat(1, embedding, ndDiffused);
  20. }

代码示例来源:origin: org.nd4j/nd4j-api

  1. /**
  2. * Append the given
  3. * array with the specified value size
  4. * along a particular axis
  5. * @param arr the array to append to
  6. * @param padAmount the pad amount of the array to be returned
  7. * @param val the value to append
  8. * @param axis the axis to append to
  9. * @return the newly created array
  10. */
  11. public static INDArray append(INDArray arr, int padAmount, double val, int axis) {
  12. if (padAmount == 0)
  13. return arr;
  14. int[] paShape = ArrayUtil.copy(arr.shape());
  15. if (axis < 0)
  16. axis = axis + arr.shape().length;
  17. paShape[axis] = padAmount;
  18. INDArray concatArray = Nd4j.valueArrayOf(paShape, val);
  19. return Nd4j.concat(axis, arr, concatArray);
  20. }

代码示例来源:origin: org.nd4j/nd4j-api

  1. /**
  2. * Append the given
  3. * array with the specified value size
  4. * along a particular axis
  5. * @param arr the array to append to
  6. * @param padAmount the pad amount of the array to be returned
  7. * @param val the value to append
  8. * @param axis the axis to append to
  9. * @return the newly created array
  10. */
  11. public static INDArray prepend(INDArray arr, int padAmount, double val, int axis) {
  12. if (padAmount == 0)
  13. return arr;
  14. int[] paShape = ArrayUtil.copy(arr.shape());
  15. if (axis < 0)
  16. axis = axis + arr.shape().length;
  17. paShape[axis] = padAmount;
  18. INDArray concatArr = Nd4j.valueArrayOf(paShape, val);
  19. return Nd4j.concat(axis, concatArr, arr);
  20. }

代码示例来源:origin: improbable-research/keanu

  1. /**
  2. * @param dimension the dimension along which the tensors will be joined
  3. * @param toConcat an array of IntegerTensor
  4. * @return an IntegerTensor with toConcat joined along existing dimension
  5. * <p>
  6. * e.g. A, B, C = IntegerTensor.ones(4, 2)
  7. * <p>
  8. * IntegerTensor.concat(0, A, B, C) gives IntegerTensor.ones(12, 2)
  9. */
  10. static IntegerTensor concat(int dimension, IntegerTensor... toConcat) {
  11. INDArray[] concatAsINDArray = new INDArray[toConcat.length];
  12. for (int i = 0; i < toConcat.length; i++) {
  13. concatAsINDArray[i] = Nd4jIntegerTensor.unsafeGetNd4J(toConcat[i]).dup();
  14. if (concatAsINDArray[i].shape().length == 0) {
  15. concatAsINDArray[i] = concatAsINDArray[i].reshape(1);
  16. }
  17. }
  18. INDArray concat = Nd4j.concat(dimension, concatAsINDArray);
  19. return new Nd4jIntegerTensor(concat);
  20. }

代码示例来源:origin: improbable-research/keanu

  1. /**
  2. * @param dimension the dimension along which the tensors will be joined
  3. * @param toConcat an array of DoubleTensor
  4. * @return a DoubleTensor with toConcat joined along an existing dimension
  5. * <p>
  6. * e.g. A, B, C = DoubleTensor.ones(4, 2)
  7. * <p>
  8. * DoubleTensor.concat(0, A, B, C) gives DoubleTensor.ones(12, 2)
  9. */
  10. static DoubleTensor concat(int dimension, DoubleTensor... toConcat) {
  11. INDArray[] concatAsINDArray = new INDArray[toConcat.length];
  12. for (int i = 0; i < toConcat.length; i++) {
  13. concatAsINDArray[i] = Nd4jDoubleTensor.unsafeGetNd4J(toConcat[i]).dup();
  14. if (concatAsINDArray[i].shape().length == 0) {
  15. concatAsINDArray[i] = concatAsINDArray[i].reshape(1);
  16. }
  17. }
  18. INDArray concat = Nd4j.concat(dimension, concatAsINDArray);
  19. return new Nd4jDoubleTensor(concat);
  20. }

相关文章