0

If we want to create an INDArray of given rows and columns filled with random number between 0 and 1 we can use:

Nd4j.rand(row, cols);

But what if we want INDArray of given rows and columns filled with random number between -5000 and 5000? Moreover, what if each column / vector has random number selected from specific range? For example:

row = 2; columns = 3
pool = { {-500, 500}, {100, 100}, {1, 10} }
INDArray = [ [randRange(-500,500), randRange(100,100), randRange(1,10)],
             [randRange(-500,500), randRange(100,100), randRange(1,10)] ]

How can this be achieved by harnessing the efficiency of Nd4j?

foobar
  • 571
  • 1
  • 5
  • 20

1 Answers1

2

Use other signatures.

I.e this one:

Nd4j.rand(long[] shape, double min, double max, org.nd4j.linalg.api.rng.Random rng);

or this one:

Nd4j.rand(INDArray target, double min, double max, org.nd4j.linalg.api.rng.Random rng);

raver119
  • 336
  • 1
  • 5
  • perfect! but what if each element of INDArray has to be generated from different random range? (last part of my question) – foobar Apr 30 '20 at 09:59
  • 1
    There's no "out of box" way to do that, but you can obvious master it yourself, i.e. by applying certain scale to each element individually. – raver119 May 04 '20 at 14:10