https://github.com/angelhtml/tensorflow_tutorial
https://github.com/angelhtml/tensorflow_tutorial
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/angelhtml/tensorflow_tutorial
- Owner: angelhtml
- Created: 2022-09-19T18:37:50.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-06-18T18:50:50.000Z (about 3 years ago)
- Last Synced: 2025-03-01T00:32:48.759Z (over 1 year ago)
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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)