Subscribe to this blog

Follow by Email

Arithmetic Operations in Tensorflow

In this article, we will learn about basic arithmetic operators supported by the Tensorflow. We will also perform these operations on the tensors and create a computational graph which can be viewed with the help of the Tensorboard.

This is the basic implementation of arithmetic operations in TensorFlow and for more arithmetic operations you can check the TensorFlow site.

Sometimes, we may want to perform arithmetic operations on more than two nodes. In that case, we have to perform an arithmetic operation on first two nodes then on the result, the next consecutive node and so on.

Let's say we want to add three nodes or four nodes or five nodes, If we use the official formula, we end with some thing like this

Both give same results and you can use any one or both in your code. This extends to other operators too (eg: - or tf.subtract, * or tf.multiply).

You can also set your output to be

output = node_add + node_subtract + node_multiply + node_divide

If you use this, you'll get a Type Error saying that Tensor conversion requested dtype int32 for Tensor with dtype float64. To get rid of this, you need to convert the node_divide which is of type Float32 to int32.

Now, let's start a session to print the output value and create the computational graph.

All the outputs (output1, output2, output3) give you the same result but their computational graph will be different.

For output1 node_add is added to node_subtract first and the result will be added to node_multiply. For output3 node_multiply is added to node_add first and the result is added to node_subtract. You can see the effect on the computational graph in the below figures.

Comments

Post a Comment

Popular posts from this blog

If you're someone who likes the hourly sounds that are made by watches or wall clocks every hour then you might show interest in an app like the Blip Blip. This app brings the hourly chimes feature to Android. The app is build by Paweł Nadolski and is available for free in the Google Play Store with no In-app purchases.

Blip Blip app has a simple UI and it notifies you every hour with a sound. Currently, the notification sounds have 6 variations and its creator mentioned there is more to come. In addition to the sound, you can also enable vibration.

You can turn the app on off from its main screen. Once on, the notification repeats every hour or you can set for shorter times.

You can check the upcoming notification times for almost a week and if you don't want the app to notify you in the night or any other specific time then you can set the silent time in settings. In addition to that, you can also add silent days.

ProtonMail is an end-to-end encrypted email service that aims to protect users privacy. The application is offered by Proton Technologies and is available for free in the Google Play Store.
Simply create an email address and start sending, receiving emails and attachments that are encrypted for free. You can set timers for the emails to self-destruct and send password protected emails.

The free email account comes with limited features. You can send and receive 150 secure emails per day, create 20 labels and a limited storage of 500MB.
You can upgrade the account to a plus account or a visionary account to increase the limits and can also create custom domains. The plus account costs around € 5.00 /mo or € 48.00 /yr and the visionary account costs € 30.00 /mo or € 288.00 /yr.
Great Day Readers! To give insights into the application development, Dr. Andy Yen,…

In this blog post, I'll be explaining how to change the color of an indeterminate circular progress bar not just once but every few seconds. This type of behavior is commonly seen in the Google's Inbox by Gmail app.
It is simple to build. All we've to do is update the progress bar color every few seconds. This can be achieved by using the setIndeterminateTintList method and a Handler.

The setIndeterminateTintList method changes the progress bar color while the handler makes sure this method is called continuously.

Below is a sample code which mimics such behavior.
One more thing to point out is that setIndeterminateTintList was added in API 21 which means it doesn't work on pre-lollipop devices.

Only limited colors are added to the colorList and you can always add more colors or change the colors in the colorList. If you don't have the desired list of colors, you can randomize the color selection process.