# How to set Tensorflow 2 on Colab.research.google.com

> This simple tutorial show you how to set Tensorflow 2 version in google Colab. It is simple step by step, picture by picture guide.

- Canonical URL: https://www.funvisiontutorials.com/blog/set-tensorflow-2-colab-research-google-com/
- Author: Vladimir Kucera
- Published: 2020-03-21
- Updated: 2020-12-02
- Topics: Deep learning, Python

This simple tutorial show you how to set Tensorflow 2 version in google Colab. It is simple step by step, picture by picture guide.

I try to find a way to set Tensorflow 2 version on Colab. Are you using Colab? I love it.

### Set a version of Tensorflow

To set the Tensorflow version in [colab.research.google.com](https://colab.research.google.com/)

1.  execute following code %tensorflow\_version
2.  go to top menu - Runtime - Restart and Run all

\[0\]:%tensorflow\_version 2.x

[Image: colab.research.google tensorflow 2 version]

_Point 1 set Tensorflow version_

[Image: tensorflow 2]

_point 2 restart runtime_

### Test the Tensorflow 2 version

After set version and **restart of runtime** try to use Tensorflow 2.0 and print version. If you have version of Tensorflow 1.x somethink weht wrong. Add new code section as follows

[Image: Tensorflow 2 on Colab.research.google.com]

In \[0\]:

```python
from __future__ import absolute_import, division, print_function, unicode_literals
try:
  # %tensorflow_version only exists in Colab.
  %tensorflow_version 2.x
except Exception:
  pass
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
print(tf.__version__)

# This looks like a vector right ?
tensor_OneDimension = np.array([1,2,3,4,5])

# The acess tensor elenents by index
first_element = tensor_OneDimension[0]
last_element = tensor_OneDimension[4]

print("first element :",first_element)
print("second element:",last_element)
print("--------------------------------")

# This tensor looks like an Matrix.
tensor_TwoDimensionMatrix = np.array([[1, 2],[3, 4]])
# Access matrix elements by index
print(tensor_TwoDimensionMatrix)
print("--------------------------------")
print(tensor_TwoDimensionMatrix[0][0])
print(tensor_TwoDimensionMatrix[1][0])
print(tensor_TwoDimensionMatrix[0][1])
print(tensor_TwoDimensionMatrix[1][1])
print("--------------------------------")

# print all elements of first Row and second Row
print("Print 1 row by [:][0]",tensor_TwoDimensionMatrix[:][0])
print("Print 2 row by [:][1]",tensor_TwoDimensionMatrix[:][0])
print("--------------------------------")
# print columen by
print("Print 1 row by [0][:]",tensor_TwoDimensionMatrix[:][0])
print("Print 2 row by [1][:]",tensor_TwoDimensionMatrix[:][0])
print("--------------------------------")
```

### Expected result of print(tf.\_\_version\_\_)

[Image: Tensorflow 2 on colab.research by google]

_print Tensorflow version 2.1.0_
