本文整理了Java中org.nd4j.linalg.factory.Nd4j.trueScalar()
方法的一些代码示例,展示了Nd4j.trueScalar()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Nd4j.trueScalar()
方法的具体详情如下:
包路径:org.nd4j.linalg.factory.Nd4j
类名称:Nd4j
方法名:trueScalar
[英]This method creates new 0D INDArray, aka scalar. PLEASE NOTE: Temporary method, added to ensure backward compatibility
[中]
代码示例来源:origin: deeplearning4j/nd4j
@Override
public INDArray getScalar(long... indexes) {
return Nd4j.trueScalar(getDouble(indexes));
}
代码示例来源:origin: deeplearning4j/nd4j
public static INDArray createUninitializedDetached(long[] shape, char ordering) {
if (shape.length == 0)
return trueScalar(0.0);
//ensure shapes that wind up being scalar end up with the write shape
if (shape.length == 1 && shape[0] == 0) {
shape = new long[] {1, 1};
} else if (shape.length == 1) {
shape = new long[] {1, shape[0]};
}
checkShapeValues(shape);
INDArray ret = INSTANCE.createUninitializedDetached(shape, ordering);
logCreationIfNecessary(ret);
return ret;
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Creates an ndarray with the specified value
* as the only value in the ndarray.
* Some people may know this as np.full
*
* @param shape the shape of the ndarray
* @param value the value to assign
* @return the created ndarray
*/
public static INDArray valueArrayOf(int[] shape, double value) {
if (shape.length == 0)
return trueScalar(value);
checkShapeValues(shape);
INDArray ret = INSTANCE.valueArrayOf(shape, value);
logCreationIfNecessary(ret);
return ret;
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Creates an ndarray with the specified value
* as the only value in the ndarray.
* Some people may know this as np.full
*
* @param shape the shape of the ndarray
* @param value the value to assign
* @return the created ndarray
*/
public static INDArray valueArrayOf(long[] shape, double value) {
if (shape.length == 0)
return trueScalar(value);
checkShapeValues(shape);
INDArray ret = INSTANCE.valueArrayOf(shape, value);
logCreationIfNecessary(ret);
return ret;
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Cretes uninitialized INDArray detached from any (if any) workspace
*
* @param shape
* @param ordering
* @return
*/
public static INDArray createUninitializedDetached(int[] shape, char ordering) {
if (shape.length == 0)
return trueScalar(0.0);
//ensure shapes that wind up being scalar end up with the write shape
if (shape.length == 1 && shape[0] == 0) {
shape = new int[] {1, 1};
} else if (shape.length == 1) {
shape = new int[] {1, shape[0]};
}
checkShapeValues(shape);
INDArray ret = INSTANCE.createUninitializedDetached(shape, ordering);
logCreationIfNecessary(ret);
return ret;
}
代码示例来源:origin: deeplearning4j/nd4j
String shapeString = line.split(":")[1].replace("[", "").replace("],", "");
if (shapeString.isEmpty()) {
newArr = Nd4j.trueScalar(0);
} else {
String[] shapeArr = shapeString.split(",");
代码示例来源:origin: deeplearning4j/nd4j
public static INDArray createUninitialized(long[] shape, char ordering) {
if (shape.length == 0)
return trueScalar(0.0);
shape = getEnsuredShape(shape);
// now we allow 1D vectors
/*else if (shape.length == 1) {
shape = new int[] {1, shape[0]};
}
*/
checkShapeValues(shape);
INDArray ret = INSTANCE.createUninitialized(shape, ordering);
logCreationIfNecessary(ret);
return ret;
}
代码示例来源:origin: deeplearning4j/nd4j
public static INDArray create(float[] data, long[] shape) {
if (shape.length == 0 && data.length == 1) {
return trueScalar(data[0]);
}
shape = getEnsuredShape(shape);
if (shape.length == 1) {
if (shape[0] != data.length)
throw new ND4JIllegalStateException("Shape of the new array doesn't match data length");
}
checkShapeValues(data.length, shape);
INDArray ret = INSTANCE.create(data, shape);
logCreationIfNecessary(ret);
return ret;
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Creates an ndarray with the specified shape
*
* @param shape the shape of the ndarray
* @param stride the stride for the ndarray
* @param offset the offset of the ndarray
* @return the instance
*/
public static INDArray create(double[] data, int[] shape, int[] stride, long offset, char ordering) {
if (data.length == 1 && shape.length == 0)
return trueScalar(data[0]);
shape = getEnsuredShape(shape);
if (shape.length == 1) {
if (shape[0] != data.length)
throw new ND4JIllegalStateException("Shape of the new array " + Arrays.toString(shape)
+ " doesn't match data length: " + data.length);
}
checkShapeValues(data.length, shape);
INDArray ret = INSTANCE.create(data, shape, stride, offset, ordering);
logCreationIfNecessary(ret);
return ret;
}
代码示例来源:origin: deeplearning4j/nd4j
if (rank == 0) {
all.add(new Pair<>(Nd4j.trueScalar(Nd4j.rand(1, 1).getDouble(0)), "{}"));
return all;
代码示例来源:origin: deeplearning4j/nd4j
public static INDArray create(double[] data, long[] shape) {
if (shape.length == 0 && data.length == 1) {
return trueScalar(data[0]);
}
shape = getEnsuredShape(shape);
if (shape.length == 1) {
if (shape[0] != data.length)
throw new ND4JIllegalStateException("Shape of the new array doesn't match data length");
}
checkShapeValues(data.length, shape);
INDArray ret = INSTANCE.create(data, shape);
logCreationIfNecessary(ret);
return ret;
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Creates an *uninitialized* ndarray with the specified shape and ordering.<br>
* <b>NOTE</b>: The underlying memory (DataBuffer) will not be initialized. Don't use this unless you know what you are doing.
*
* @param shape the shape of the ndarray
* @param ordering the order of the ndarray
* @return the instance
*/
public static INDArray createUninitialized(int[] shape, char ordering) {
if (shape.length == 0)
return trueScalar(0.0);
shape = getEnsuredShape(shape);
// now we allow 1D vectors
/*else if (shape.length == 1) {
shape = new int[] {1, shape[0]};
}
*/
checkShapeValues(shape);
INDArray ret = INSTANCE.createUninitialized(shape, ordering);
logCreationIfNecessary(ret);
return ret;
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Create an ndrray with the specified shape
*
* @param data the data to use with tne ndarray
* @param shape the shape of the ndarray
* @return the created ndarray
*/
public static INDArray create(float[] data, int[] shape) {
if (shape.length == 0 && data.length == 1) {
return trueScalar(data[0]);
}
shape = getEnsuredShape(shape);
if (shape.length == 1) {
if (shape[0] != data.length)
throw new ND4JIllegalStateException("Shape of the new array doesn't match data length");
}
checkShapeValues(data.length, shape);
INDArray ret = INSTANCE.create(data, shape);
logCreationIfNecessary(ret);
return ret;
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Note that iArgs (integer arguments) and tArgs(double/float arguments)
* may end up being used under the following conditions:
* scalar operations (if a scalar is specified the you do not need to specify an ndarray)
* otherwise, if an ndarray is needed as a second input then put it in the inputs
*
* Usually, you only need 1 input (the equivalent of the array you're trying to do indexing on)
*
* @param inputs the inputs in to the op
* @param iArgs the integer arguments as needed
* @param tArgs the arguments
* @param condition the condition to filter on
*/
public Choose(INDArray[] inputs,List<Integer> iArgs, List<Double> tArgs,Condition condition) {
super(null, inputs, null);
if(condition == null) {
throw new ND4JIllegalArgumentException("Must specify a condition.");
}
if(!iArgs.isEmpty())
addIArgument(Ints.toArray(iArgs));
if(!tArgs.isEmpty())
addTArgument(Doubles.toArray(tArgs));
addIArgument(condition.condtionNum());
addOutputArgument(Nd4j.create(inputs[0].shape(), inputs[0].ordering()),Nd4j.trueScalar(1.0));
}
代码示例来源:origin: deeplearning4j/nd4j
return Nd4j.trueScalar(0.0);
return Nd4j.trueScalar(fa[0]);
return Nd4j.trueScalar(fa[0]);
return Nd4j.trueScalar(0.0);
INDArray array = Nd4j.trueScalar(val);
return array;
} else if (tfTensor.getDoubleValCount() > 0) {
return Nd4j.trueScalar(da[0]);
return Nd4j.trueScalar(0.0);
INDArray array = Nd4j.trueScalar(val);
return array;
} else if (tfTensor.getInt64ValCount() > 0) {
return Nd4j.trueScalar(fa[0]);
代码示例来源:origin: improbable-research/keanu
public static INDArray scalar(double scalarValue, DataBuffer.Type bufferType) {
Nd4j.setDataType(bufferType);
return Nd4j.trueScalar(scalarValue);
}
内容来源于网络,如有侵权,请联系作者删除!