# -*- coding: utf-8 -*-
"""BASIC OPERATIONS PERFORMED ON TENSORS

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/gist/Bobbyorr007/c9a87cad5895bb9dd53f81dd7a2e8e0e/basic-operations-performed-on-tensors.ipynb

**IMPORTS**
"""

import numpy as np
import tensorflow as tf

"""**EXERCISE ON BASIC TENSORS**

I created a single dimensional numpy array of size 50, holding values from 0 to 49. 
"""

# Create a 1d uint8 NumPy array comprising of the first 50 natural numbers
x = np.arange(0,50)
x

"""I Changed my numpy array into a tensor"""

# Convert NumPy array into a tensor using the 'tf.constant'
x = tf.constant(x)
x

"""I squared(element-wise) all the values in my tensor x."""

# Square the input tensor x
x = tf.square(x)
x

"""One feature of tensors is that it can be reshaped. while reshaping make sure to use dimensions that will include all values of your Tensor.

"""

# Reshape Tensor into (5 x 10) matrics...
x = tf.reshape(x, (5,10))
x

"""Just like reshaping Tensor, we can also change the data type of Tensors. I will change the data type of my tensor(x) from an int to float."""

# cast tensor x into a float32 dtype
x = tf.cast(x, tf.float32)
x

"""I created a single value Tensor(float32) in other to show the power of broadcasting. """

# I created a single value tensor of dtype float32 to show thw power of broadcasting in the following cell.
y = tf.constant(2, dtype=tf.float32)
y

"""I mutiplied the tensor x and y together and experienced the power of broadcasting. The single value tensor (y), multiplied each value/element of the tensor x."""

# Multiply tensor x by y. tensor y is multilied to each element of tensor x.
result = tf.multiply(x,y)
result

"""I reinitiaized Tensor y to having more values."""

# Reinitialize y to having more values
y = tf.constant([1,2,3,4,5,6,7,8,9,0], dtype=tf.float32)
y

"""I added both tensors together and noticed the addition was done in rows.
The tensor 'y' summed up with the first row of tensor 'x' then moved on to the next row, and the next and so on.
"""

# Add tensor x and y together, and notice the summation in rows.
result = x + y
result

"""When usinf tf.constant, we can pass in a 1D array and using the shape parameter to change into a multi-dimensional array."""

# creating a 1D array with tf.constant and using the shape parameter to change into a 2D array.
x = tf.constant([1234], tf.float32, shape=(2,2))
x

"""This isnt the case with a tf.Variable created Tensor

"""

# creating a 1D array with tf.Variable and using the shape parameter to change into a multi-dimension. NOTICE THE ValueError THATS POPS UP WHEN THE CODE BLOCK IS RAN
x = tf.Variable([1,2,3,4], tf.float32, shape=(2,2))

