JavaScript

Tensorflow.js – tfd.atanh()

Tensorflow.js is a framework in Javascript that supports the tf.atanh() function that converts all the numeric values to inverse hyperbolic tangent values present in a tensor.

Tf.atanh() Function

The tf.atanh() is used to return the inverse hyperbolic tangent values from a given tensor. It takes only one parameter, i.e. tensor, that has numbers.

Syntax:
tf.atanh(tensor_input)

Parameter:
The tensor_input is a tensor that has numbers.

It can be 1or 2 dimensional.

Let’s explore the different examples of this method.

Example 1:

Let’s create a one-dimensional tensor in js that has some values and return the inverse hyperbolic tangent values.

<html>
<!--   CDN Link that delivers the Tensorflow.js framework -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>

<body>
<center><h1>Tensorflow.js - tf.atanh() </h1></center>
<script>

let values = tf.tensor1d([23,45,0,45]);

//actual tensor
document.write("Actual Tensor: ",values);

document.write("<br>");
document.write("<br>");

//apply atanh() on the above tensor
document.write("Tensor with Inverse Hyperbolic Tangent Values: "+tf.atanh(values));
</script>

</body>
</html>

Output:

The inverse hyperbolic tangent values were returned from the given one-dimensional tensor.

Example 2:

Let’s create a tensor that has 2 dimensions in js with 5 rows and 2 columns and return the inverse hyperbolic tangent values.

<html>
<!--   CDN Link that delivers the Tensorflow.js framework -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>

<body>
<center><h1>Tensorflow.js - tf.atanh() </h1></center>
<script>

let values = tf.tensor2d([[0,null],[10,NaN],[45,82],[34,undefined],[67,43]]);

//actual tensor
document.write("Actual Tensor: ",values);

document.write("<br>");
document.write("<br>");

//apply atanh() on the above tensor
document.write("Tensor with Inverse Hyperbolic Tangent Values: "+tf.atanh(values));
</script>

</body>
</html>

Output:

The inverse hyperbolic tangent values were returned from the given one-dimensional tensor.

Example 3:

In this case, we will consider the decimal values. Let’s create a tensor that has 2 dimensions in js with 5 rows and 2 columns and return the inverse hyperbolic tangent values.

<html>
<!--   CDN Link that delivers the Tensorflow.js framework -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>

<body>
<center><h1>Tensorflow.js - tf.atanh() </h1></center>


let values = tf.tensor2d([[4.80,0], [45.10,null], [46.785,8.2], [31.4,5.6], [6.87,43.76]]);
//actual tensor
document.write("Actual Tensor: ",values);

document.write("<br>");
document.write("<br>");

//apply atanh() on the above tensor
document.write("Tensor with Inverse Hyperbolic Tangent Values: "+tf.atanh(values));
</script>

</body>
</html>

Output:

The inverse hyperbolic tangent values were returned from the given one-dimensional tensor.

Conclusion

In this Tensorflow.js tutorial, we learned how to return the inverse hyperbolic tangent values from the actual values using the tf.atanh() function present in one/two dimensional tensors with three examples. Make sure that the CDN Link is provided inside the script tag in each and every code.

About the author

Gottumukkala Sravan Kumar

B tech-hon's in Information Technology; Known programming languages - Python, R , PHP MySQL; Published 500+ articles on computer science domain