An open API service indexing awesome lists of open source software.

https://github.com/angelhtml/tensorflow_tutorial


https://github.com/angelhtml/tensorflow_tutorial

Last synced: 4 months ago
JSON representation

Awesome Lists containing this project

README

          

Tensorflow tutorial

Create a tensor of n-dimension 📜


You begin with the creation of a tensor with one dimension, namely a scalar

To create a tensor, you can use tf.constant() as shown in the below TensorFlow tensor shape example:

``` python

tf.constant(value, dtype, name = "")
tf.constant(value, shape=(col, row) )
'''
- `value`: Value of n dimension to define the tensor. Optional
- `dtype`: Define the type of data:
- `tf.float32`: Float variable
- `tf.int16`: Integer variable
- `tf.string`: String variable
- `tf.bool`: Boolean variable
- "name": Name of the tensor. Optional. By default, `Const_1:0`
'''

```

Below, a float tensor is converted to integer using you use the method cast ()

``` python

# Change type of data
type_float = tf.constant(3.123456789, tf.float32)
type_int = tf.cast(type_float, dtype=tf.int32)
print(type_float.dtype)
print(type_int.dtype)

```

Creating operator âž—


Some Useful TensorFlow operators
You know how to create a tensor with TensorFlow. It is time to learn how to perform mathematical operations.
TensorFlow contains all the basic operations. You can begin with a simple one. You will use TensorFlow method to compute the square of a number. This operation is straightforward because only one argument is required to construct the tensor.
The square of a number is constructed with tf.sqrt(x) with x as a floating number

``` python

x = tf.constant([4.0], dtype = tf.float32)
print(tf.sqrt(x))

```

The output returned a tensor object and not the result of the square of 4. In the example, you print the definition of the tensor and not the actual evaluation of the operation. In the next section, you will learn how TensorFlow works to execute the operations.
Following is a list of commonly used operations. The idea is the same. Each operation requires one or more arguments


  • tf.add(a, b)

  • tf.substract(a, b)

  • tf.multiply(a, b)

  • tf.div(a, b)

  • tf.pow(a, b)

  • tf.exp(a)

  • tf.sqrt(a)