JavaScript

Tensorflow.js – tf.acosh()

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

Tf.acosh() Function

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

Syntax:
tf.acosh(tensor_input)

Parameter:
The tensor_input is a tensor that has numbers.
It can be 1 or 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 cosine 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.acosh() </h1></center>
<script>

let values = tf.tensor1d([78,54,67,90,21,45,67,89,0,1]);

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

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

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

</body>
</html>

Output:

The inverse hyperbolic cosine 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 cosinevalues.

<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.acosh() </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 acosh() on the above tensor
document.write("Tensor with Inverse Hyperbolic Cosine Values: "+tf.acosh(values));
</script>

</body>
</html>

Output:

The inverse hyperbolic cosine 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 cosine 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.acosh() </h1></center>
<script>

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 acosh() on the above tensor
document.write("Tensor with Inverse Hyperbolic Cosine Values: "+tf.acosh(values));
</script>

</body>
</html>

Output:

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

Conclusion

In this Tensorflow.js tutorial, we learned how to return the inverse hyperbolic cosine values from the actual values using the tf.acosh() 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