static INDArray resize(INDArray arr, int [] shape) { INDArray resized = Nd4j.create(shape); resized.get(NDArrayIndex.createCoveringShape(arr.shape())).assign(arr); return resized; }
/** * Pads an ndarray with zeros * * @param nd the ndarray to pad * @param targetShape the the new shape * @return the padded ndarray */ public static IComplexNDArray padWithZeros(IComplexNDArray nd, long[] targetShape) { if (Arrays.equals(nd.shape(), targetShape)) return nd; //no padding required if (ArrayUtil.prod(nd.shape()) >= ArrayUtil.prod(targetShape)) return nd; IComplexNDArray ret = Nd4j.createComplex(targetShape); INDArrayIndex[] targetShapeIndex = NDArrayIndex.createCoveringShape(nd.shape()); ret.put(targetShapeIndex, nd); return ret; }
/** * Pads an ndarray with zeros * * @param nd the ndarray to pad * @param targetShape the the new shape * @return the padded ndarray */ public static IComplexNDArray padWithZeros(IComplexNDArray nd, int[] targetShape) { if (Arrays.equals(nd.shape(), targetShape)) return nd; //no padding required if (ArrayUtil.prod(nd.shape()) >= ArrayUtil.prod(targetShape)) return nd; IComplexNDArray ret = Nd4j.createComplex(targetShape); INDArrayIndex[] targetShapeIndex = NDArrayIndex.createCoveringShape(nd.shape()); ret.put(targetShapeIndex, nd); return ret; }