Before implementing machine-learning algorithms, let’s get familiar with how to use TensorFlow. You’re going to get your hands dirty writing simple code right away! This chapter covers some essential advantages of TensorFlow to convince you that it’s the machine-learning library of choice. Before you continue, follow the procedures in the appendix for step-by-step installation instructions, then return here.
As a thought experiment, let’s see what happens when we use Python code without a handy computing library. It’ll be like using a new smartphone without installing any additional apps. The functionality will be there, but you’d be much more productive if you had the right tools.
Suppose you’re a private business owner tracking the flow of sales for your products. Your inventory consists of 100 items, and you represent each item’s price in a vector called prices
. Another 100-dimensional vector called amounts
represents the inventory count of each item. You can write the chunk of Python code shown in listing 2.1 to calculate the revenue of selling all products. Keep in mind that this code doesn’t import any libraries.
revenue = 0 for price, amount in zip(prices, amounts): revenue += price * amount