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

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

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

Nd4j.create介绍

[英]Creates a row vector with the specified number of columns
[中]创建具有指定列数的行向量

代码示例

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

  1. protected INDArray create(DataBuffer data, int[] shape, long offset) {
  2. if (this instanceof IComplexNDArray)
  3. return Nd4j.createComplex(data, shape, offset);
  4. else
  5. return Nd4j.create(data, shape, offset);
  6. }

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

  1. /**
  2. *
  3. * @param shape
  4. * @param stride
  5. * @param ordering
  6. * @return
  7. */
  8. public static INDArray zeros(int[] shape, int[] stride, char ordering) {
  9. return create(shape, stride, ordering);
  10. }

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

  1. /**
  2. * Creates a row vector with the specified number of columns
  3. *
  4. * @param columns the columns of the ndarray
  5. * @return the created ndarray
  6. */
  7. public static INDArray create(int columns) {
  8. return create(columns, order());
  9. }

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

  1. protected INDArray create(DataBuffer data, int[] newShape, int[] newStrides, long offset, char ordering) {
  2. if (this instanceof IComplexNDArray)
  3. return Nd4j.createComplex(data, newShape, newStrides, offset, ordering);
  4. else
  5. return Nd4j.create(data, newShape, newStrides, offset, ordering);
  6. }

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

  1. /**
  2. * Creates an ndarray with the specified shape
  3. *
  4. * @param rows the rows of the ndarray
  5. * @param columns the columns of the ndarray
  6. * @param stride the stride for the ndarray
  7. * @return the instance
  8. */
  9. public static INDArray create(int rows, int columns, int[] stride) {
  10. return create(rows, columns, stride, order());
  11. }

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

  1. protected INDArray create(DataBuffer data, int[] newShape, int[] newStrides, long offset) {
  2. if (this instanceof IComplexNDArray)
  3. return Nd4j.createComplex(data, newShape, newStrides, offset);
  4. else
  5. return Nd4j.create(data, newShape, newStrides, offset);
  6. }

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

  1. /**
  2. * Creates an ndarray with the specified shape
  3. *
  4. * @param rows the rows of the ndarray
  5. * @param columns the columns of the ndarray
  6. * @return the instance
  7. */
  8. public static INDArray create(int rows, int columns) {
  9. return create(rows, columns, order());
  10. }

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

  1. /**
  2. * Computes the eigenvalues of a general matrix.
  3. */
  4. public static IComplexNDArray eigenvalues(INDArray A) {
  5. assert A.rows() == A.columns();
  6. INDArray WR = Nd4j.create(A.rows(), A.rows());
  7. INDArray WI = WR.dup();
  8. Nd4j.getBlasWrapper().geev('N', 'N', A.dup(), WR, WI, dummy, dummy);
  9. return Nd4j.createComplex(WR, WI);
  10. }

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

  1. @Override
  2. public INDArray sample(long[] shape) {
  3. INDArray ret = Nd4j.create(shape);
  4. return sample(ret);
  5. }

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

  1. /**
  2. * Creates a row vector with the data
  3. *
  4. * @param data the columns of the ndarray
  5. * @return the created ndarray
  6. */
  7. public static INDArray create(float[] data) {
  8. return create(data, order());
  9. }

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

  1. /**
  2. * Creates a row vector with the data
  3. *
  4. * @param data the columns of the ndarray
  5. * @return the created ndarray
  6. */
  7. public static INDArray create(double[] data) {
  8. return create(data, order());
  9. }

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

  1. /**
  2. * Creates an ndarray with the specified shape
  3. *
  4. * @param shape the shape of the ndarray
  5. * @return the instance
  6. */
  7. public static INDArray create(long... shape) {
  8. return create(shape, order());
  9. }

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

  1. @Override
  2. public INDArray sample(int[] shape) {
  3. INDArray ret = Nd4j.create(shape);
  4. return sample(ret);
  5. }

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

  1. public static INDArray toNDArray(int[][] nums) {
  2. if (Nd4j.dataType() == DataBuffer.Type.DOUBLE) {
  3. double[] doubles = ArrayUtil.toDoubles(nums);
  4. INDArray create = Nd4j.create(doubles, new int[] {nums[0].length, nums.length});
  5. return create;
  6. } else {
  7. float[] doubles = ArrayUtil.toFloats(nums);
  8. INDArray create = Nd4j.create(doubles, new int[] {nums[0].length, nums.length});
  9. return create;
  10. }
  11. }

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

  1. private void growCapacity(int idx) {
  2. if(container == null) {
  3. container = Nd4j.create(10);
  4. }
  5. else if(idx >= container.length()) {
  6. val max = Math.max(container.length() * 2,idx);
  7. INDArray newContainer = Nd4j.create(max);
  8. newContainer.put(new INDArrayIndex[]{NDArrayIndex.interval(0,container.length())},container);
  9. container = newContainer;
  10. }
  11. }

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

  1. protected INDArray createScalarForIndex(long i, boolean applyOffset) {
  2. if(isVector())
  3. return getScalar(i);
  4. return Nd4j.create(data(), new long[] {1, 1}, new long[] {1, 1}, i);
  5. }

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

  1. @Override
  2. public INDArray nextFloat(char order, long[] shape) {
  3. long length = ArrayUtil.prodLong(shape);
  4. INDArray ret = Nd4j.create(shape, order);
  5. DataBuffer data = ret.data();
  6. for (long i = 0; i < length; i++) {
  7. data.put(i, nextFloat());
  8. }
  9. return ret;
  10. }

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

  1. public static INDArray convertFromApacheMatrix(RealMatrix matrix) {
  2. int[] shape = new int[] {matrix.getRowDimension(), matrix.getColumnDimension()};
  3. INDArray out = Nd4j.create(shape);
  4. for (int i = 0; i < shape[0]; i++) {
  5. for (int j = 0; j < shape[1]; j++) {
  6. double value = matrix.getEntry(i, j);
  7. out.putScalar(new int[] {i, j}, value);
  8. }
  9. }
  10. return out;
  11. }

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

  1. @Override
  2. public INDArray getReal() {
  3. INDArray result = Nd4j.create(shape());
  4. IComplexNDArray linearView = linearView();
  5. INDArray linearRet = result.linearView();
  6. for (int i = 0; i < linearView.length(); i++) {
  7. linearRet.putScalar(i, linearView.getReal(i));
  8. }
  9. return result;
  10. }

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

  1. public static INDArray im2col(INDArray img, int kh, int kw, int sy, int sx, int ph, int pw, int dh, int dw, boolean isSameMode) {
  2. Nd4j.getCompressor().autoDecompress(img);
  3. //Input: NCHW format
  4. // FIXME: int cast
  5. int outH = outputSize((int) img.size(2), kh, sy, ph, dh, isSameMode);
  6. int outW = outputSize((int) img.size(3), kw, sx, pw, dw, isSameMode);
  7. //[miniBatch,depth,kH,kW,outH,outW]
  8. INDArray out = Nd4j.create(new long[]{img.size(0), img.size(1), kh, kw, outH, outW}, 'c');
  9. return im2col(img, kh, kw, sy, sx, ph, pw, dh, dw, isSameMode, out);
  10. }

相关文章