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

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

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

Nd4j.trueScalar介绍

[英]This method creates new 0D INDArray, aka scalar. PLEASE NOTE: Temporary method, added to ensure backward compatibility
[中]

代码示例

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

  1. @Override
  2. public INDArray getScalar(long... indexes) {
  3. return Nd4j.trueScalar(getDouble(indexes));
  4. }

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

  1. public static INDArray createUninitializedDetached(long[] shape, char ordering) {
  2. if (shape.length == 0)
  3. return trueScalar(0.0);
  4. //ensure shapes that wind up being scalar end up with the write shape
  5. if (shape.length == 1 && shape[0] == 0) {
  6. shape = new long[] {1, 1};
  7. } else if (shape.length == 1) {
  8. shape = new long[] {1, shape[0]};
  9. }
  10. checkShapeValues(shape);
  11. INDArray ret = INSTANCE.createUninitializedDetached(shape, ordering);
  12. logCreationIfNecessary(ret);
  13. return ret;
  14. }

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

  1. /**
  2. * Creates an ndarray with the specified value
  3. * as the only value in the ndarray.
  4. * Some people may know this as np.full
  5. *
  6. * @param shape the shape of the ndarray
  7. * @param value the value to assign
  8. * @return the created ndarray
  9. */
  10. public static INDArray valueArrayOf(int[] shape, double value) {
  11. if (shape.length == 0)
  12. return trueScalar(value);
  13. checkShapeValues(shape);
  14. INDArray ret = INSTANCE.valueArrayOf(shape, value);
  15. logCreationIfNecessary(ret);
  16. return ret;
  17. }

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

  1. /**
  2. * Creates an ndarray with the specified value
  3. * as the only value in the ndarray.
  4. * Some people may know this as np.full
  5. *
  6. * @param shape the shape of the ndarray
  7. * @param value the value to assign
  8. * @return the created ndarray
  9. */
  10. public static INDArray valueArrayOf(long[] shape, double value) {
  11. if (shape.length == 0)
  12. return trueScalar(value);
  13. checkShapeValues(shape);
  14. INDArray ret = INSTANCE.valueArrayOf(shape, value);
  15. logCreationIfNecessary(ret);
  16. return ret;
  17. }

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

  1. /**
  2. * Cretes uninitialized INDArray detached from any (if any) workspace
  3. *
  4. * @param shape
  5. * @param ordering
  6. * @return
  7. */
  8. public static INDArray createUninitializedDetached(int[] shape, char ordering) {
  9. if (shape.length == 0)
  10. return trueScalar(0.0);
  11. //ensure shapes that wind up being scalar end up with the write shape
  12. if (shape.length == 1 && shape[0] == 0) {
  13. shape = new int[] {1, 1};
  14. } else if (shape.length == 1) {
  15. shape = new int[] {1, shape[0]};
  16. }
  17. checkShapeValues(shape);
  18. INDArray ret = INSTANCE.createUninitializedDetached(shape, ordering);
  19. logCreationIfNecessary(ret);
  20. return ret;
  21. }

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

  1. String shapeString = line.split(":")[1].replace("[", "").replace("],", "");
  2. if (shapeString.isEmpty()) {
  3. newArr = Nd4j.trueScalar(0);
  4. } else {
  5. String[] shapeArr = shapeString.split(",");

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

  1. public static INDArray createUninitialized(long[] shape, char ordering) {
  2. if (shape.length == 0)
  3. return trueScalar(0.0);
  4. shape = getEnsuredShape(shape);
  5. // now we allow 1D vectors
  6. /*else if (shape.length == 1) {
  7. shape = new int[] {1, shape[0]};
  8. }
  9. */
  10. checkShapeValues(shape);
  11. INDArray ret = INSTANCE.createUninitialized(shape, ordering);
  12. logCreationIfNecessary(ret);
  13. return ret;
  14. }

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

  1. public static INDArray create(float[] data, long[] shape) {
  2. if (shape.length == 0 && data.length == 1) {
  3. return trueScalar(data[0]);
  4. }
  5. shape = getEnsuredShape(shape);
  6. if (shape.length == 1) {
  7. if (shape[0] != data.length)
  8. throw new ND4JIllegalStateException("Shape of the new array doesn't match data length");
  9. }
  10. checkShapeValues(data.length, shape);
  11. INDArray ret = INSTANCE.create(data, shape);
  12. logCreationIfNecessary(ret);
  13. return ret;
  14. }

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

  1. /**
  2. * Creates an ndarray with the specified shape
  3. *
  4. * @param shape the shape of the ndarray
  5. * @param stride the stride for the ndarray
  6. * @param offset the offset of the ndarray
  7. * @return the instance
  8. */
  9. public static INDArray create(double[] data, int[] shape, int[] stride, long offset, char ordering) {
  10. if (data.length == 1 && shape.length == 0)
  11. return trueScalar(data[0]);
  12. shape = getEnsuredShape(shape);
  13. if (shape.length == 1) {
  14. if (shape[0] != data.length)
  15. throw new ND4JIllegalStateException("Shape of the new array " + Arrays.toString(shape)
  16. + " doesn't match data length: " + data.length);
  17. }
  18. checkShapeValues(data.length, shape);
  19. INDArray ret = INSTANCE.create(data, shape, stride, offset, ordering);
  20. logCreationIfNecessary(ret);
  21. return ret;
  22. }

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

  1. if (rank == 0) {
  2. all.add(new Pair<>(Nd4j.trueScalar(Nd4j.rand(1, 1).getDouble(0)), "{}"));
  3. return all;

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

  1. public static INDArray create(double[] data, long[] shape) {
  2. if (shape.length == 0 && data.length == 1) {
  3. return trueScalar(data[0]);
  4. }
  5. shape = getEnsuredShape(shape);
  6. if (shape.length == 1) {
  7. if (shape[0] != data.length)
  8. throw new ND4JIllegalStateException("Shape of the new array doesn't match data length");
  9. }
  10. checkShapeValues(data.length, shape);
  11. INDArray ret = INSTANCE.create(data, shape);
  12. logCreationIfNecessary(ret);
  13. return ret;
  14. }

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

  1. /**
  2. * Creates an *uninitialized* ndarray with the specified shape and ordering.<br>
  3. * <b>NOTE</b>: The underlying memory (DataBuffer) will not be initialized. Don't use this unless you know what you are doing.
  4. *
  5. * @param shape the shape of the ndarray
  6. * @param ordering the order of the ndarray
  7. * @return the instance
  8. */
  9. public static INDArray createUninitialized(int[] shape, char ordering) {
  10. if (shape.length == 0)
  11. return trueScalar(0.0);
  12. shape = getEnsuredShape(shape);
  13. // now we allow 1D vectors
  14. /*else if (shape.length == 1) {
  15. shape = new int[] {1, shape[0]};
  16. }
  17. */
  18. checkShapeValues(shape);
  19. INDArray ret = INSTANCE.createUninitialized(shape, ordering);
  20. logCreationIfNecessary(ret);
  21. return ret;
  22. }

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

  1. /**
  2. * Create an ndrray with the specified shape
  3. *
  4. * @param data the data to use with tne ndarray
  5. * @param shape the shape of the ndarray
  6. * @return the created ndarray
  7. */
  8. public static INDArray create(float[] data, int[] shape) {
  9. if (shape.length == 0 && data.length == 1) {
  10. return trueScalar(data[0]);
  11. }
  12. shape = getEnsuredShape(shape);
  13. if (shape.length == 1) {
  14. if (shape[0] != data.length)
  15. throw new ND4JIllegalStateException("Shape of the new array doesn't match data length");
  16. }
  17. checkShapeValues(data.length, shape);
  18. INDArray ret = INSTANCE.create(data, shape);
  19. logCreationIfNecessary(ret);
  20. return ret;
  21. }

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

  1. /**
  2. * Note that iArgs (integer arguments) and tArgs(double/float arguments)
  3. * may end up being used under the following conditions:
  4. * scalar operations (if a scalar is specified the you do not need to specify an ndarray)
  5. * otherwise, if an ndarray is needed as a second input then put it in the inputs
  6. *
  7. * Usually, you only need 1 input (the equivalent of the array you're trying to do indexing on)
  8. *
  9. * @param inputs the inputs in to the op
  10. * @param iArgs the integer arguments as needed
  11. * @param tArgs the arguments
  12. * @param condition the condition to filter on
  13. */
  14. public Choose(INDArray[] inputs,List<Integer> iArgs, List<Double> tArgs,Condition condition) {
  15. super(null, inputs, null);
  16. if(condition == null) {
  17. throw new ND4JIllegalArgumentException("Must specify a condition.");
  18. }
  19. if(!iArgs.isEmpty())
  20. addIArgument(Ints.toArray(iArgs));
  21. if(!tArgs.isEmpty())
  22. addTArgument(Doubles.toArray(tArgs));
  23. addIArgument(condition.condtionNum());
  24. addOutputArgument(Nd4j.create(inputs[0].shape(), inputs[0].ordering()),Nd4j.trueScalar(1.0));
  25. }

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

  1. return Nd4j.trueScalar(0.0);
  2. return Nd4j.trueScalar(fa[0]);
  3. return Nd4j.trueScalar(fa[0]);
  4. return Nd4j.trueScalar(0.0);
  5. INDArray array = Nd4j.trueScalar(val);
  6. return array;
  7. } else if (tfTensor.getDoubleValCount() > 0) {
  8. return Nd4j.trueScalar(da[0]);
  9. return Nd4j.trueScalar(0.0);
  10. INDArray array = Nd4j.trueScalar(val);
  11. return array;
  12. } else if (tfTensor.getInt64ValCount() > 0) {
  13. return Nd4j.trueScalar(fa[0]);

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

  1. public static INDArray scalar(double scalarValue, DataBuffer.Type bufferType) {
  2. Nd4j.setDataType(bufferType);
  3. return Nd4j.trueScalar(scalarValue);
  4. }

相关文章