nd4j

What is the precise specification of `broadcast` in ND4j / DL4j?

廉价感情. 提交于 2020-03-05 03:13:49
问题 What is the precise definition of INDArray.broadcast(long...) in ND4j? The description of both methods only says "Broadcasts this ndarray to be the specified shape", and does not explain the requirements for acceptable shapes to be broadcast. The following code (meant to broadcast an ndarray to a shape of an extra first dimension of length 3) does not work: INDArray array = Nd4j.create(new double[] {1.,2.,3.,4.}, new int[] {2,2}, 'c'); System.out.println("array: " + array); System.out.println

Using broadcast in ND4J

南笙酒味 提交于 2020-02-24 17:31:27
问题 I recently switched from numpy to ND4J but had a hard time understanding how broadcasting in ND4J works. Say I have two ndarray, a of shape [3,2,4,5] and b of shape [2,4,5]. I would like to element-wise add them up and broadcast b to each a[i] for i = 0 to 2 . In numpy it can simply be done via a + b , while in ND4J a.add(b) throws an exception. I tried a.add(b.broadcast(3)) but still no luck. What is the correct way of doing this in ND4J? 回答1: The only method I have found so far is as

Using broadcast in ND4J

末鹿安然 提交于 2020-02-24 17:31:25
问题 I recently switched from numpy to ND4J but had a hard time understanding how broadcasting in ND4J works. Say I have two ndarray, a of shape [3,2,4,5] and b of shape [2,4,5]. I would like to element-wise add them up and broadcast b to each a[i] for i = 0 to 2 . In numpy it can simply be done via a + b , while in ND4J a.add(b) throws an exception. I tried a.add(b.broadcast(3)) but still no luck. What is the correct way of doing this in ND4J? 回答1: The only method I have found so far is as

Libraries not accessible for “classloader-namespace”, when loading DL4J model using restoreMultiLayerNetwork()

↘锁芯ラ 提交于 2020-02-02 12:09:47
问题 I cannot find out how to get rid of / solve the below errors, that occur when loading a Neural Network model using the DL4J method restoreMultiLayerNetwork using Android API >= 24: The errors occur when the following line within the method restoreMultiLayerNetwork is called: params = Nd4j.read(ins2); with InputStream ins2 = getResources().openRawResource(getResources().getIdentifier("coefficients", "raw", getPackageName())); and "coefficients.bin" is the coefficients file, created by the

Get an arbitrary slice of a Nd4j array

北战南征 提交于 2020-01-14 14:26:11
问题 I want to perform slicing in Nd4j of arbitrary sizes in the same manner as I am able to do using Numpy. a = numpy.arange(100) a[25:50] The nd4j slice method only takes dimension and index arguments, not length. How can I achieve this? 回答1: I know it's an old question but I ran across it while googling this problem exactly. By inspecting the source code for slice I believe it can only return full rows/columns not partial from index to index. You can use method get with an NDArrayIndex instance

ND4J arrays & their shapes: getting data into a list

风格不统一 提交于 2019-12-24 19:03:46
问题 Consider the following code, which uses the ND4J library to create a simpler version of the "moons" test data set: val n = 100 val n1: Int = n/2 val n2: Int = n-n1 val outerX = Nd4j.getExecutioner.execAndReturn(new Cos(Nd4j.linspace(0, Math.PI, n1))) val outerY = Nd4j.getExecutioner.execAndReturn(new Sin(Nd4j.linspace(0, Math.PI, n1))) val innerX = Nd4j.getExecutioner.execAndReturn(new Cos(Nd4j.linspace(0, Math.PI, n2))).mul(-1).add(1) val innerY = Nd4j.getExecutioner.execAndReturn(new Sin