0

E.g. I have x = [1 , 2, 3]. I want y = 1/x = [1, 1/2, 1/3].

Ideally, I want a function that works the same way as the following line taken from the nd4j documentation, only for the multiplicative inverse instead of the hyperbolic tangent.

 INDArray tanh = Nd4j.getExecutioner().execAndReturn(new Tanh(myArr))

If there isn't such a function, is there a more efficient, or at least cleaner, way to do a custom elementwise operation on an array than using a for loop and inverting each value individually?

Bishoy Kamel
  • 2,327
  • 2
  • 17
  • 29
Shaun
  • 23
  • 1
  • 6

1 Answers1

0

You can use the Pow transform operation with -1.0 as the exponent argument:

INDArray inv = Nd4j.getExecutioner().execAndReturn(new Pow(myArr, -1.0));
Diego Stéfano
  • 189
  • 2
  • 5