<jupyter_start><jupyter_text>Constants_Sequences_and_Random_Values<jupyter_code>from __future__ import print_function
import tensorflow as tf
import numpy as np
from datetime import date
date.today()
author = "kyubyong. https://github.com/Kyubyong/tensorflow-exercises"
tf.__version__
np.__version__
sess = tf.InteractiveSession()<jupyter_output><empty_output><jupyter_text>NOTE on notation* _x, _y, _z, ...: NumPy 0-d or 1-d arrays* _X, _Y, _Z, ...: NumPy 2-d or higer dimensional arrays* x, y, z, ...: 0-d or 1-d tensors* X, Y, Z, ...: 2-d or higher dimensional tensors  Constant Value Tensors Q1. Create a tensor of the shape [2, 3] with all elements set to zero.<jupyter_code>import tensorflow as tf
print(tf.zeros([2,3]))<jupyter_output>Tensor("zeros_3:0", shape=(2, 3), dtype=float32)<jupyter_text>Q2. Let X be a tensor of [[1,2,3], [4,5,6]]. Create a tensor of the same shape and dtype as X with all elements set to zero.<jupyter_code>import numpy as np
import tensorflow as tf
_X = np.array([[1,2,3], [4,5,6]])
x = tf.convert_to_tensor(_X)
out = tf.zeros_like(x)
out.eval()<jupyter_output><empty_output><jupyter_text>Q3. Create a tensor of shape [2, 3] with all elements set to one.<jupyter_code>import tensorflow as tf
print(tf.ones([2,3]))
tf.ones([2,3]).eval()<jupyter_output>Tensor("ones_4:0", shape=(2, 3), dtype=float32)<jupyter_text>Q4. Let X be a tensor of [[1,2,3], [4,5,6]]. Create a tensor of the same shape and dtype as X with all elements set to one.<jupyter_code>_X = np.array([[1,2,3], [4,5,6]])
_x = tf.convert_to_tensor(_X)
out = tf.ones_like(_x)
out.eval()<jupyter_output><empty_output><jupyter_text>Q5. Create a tensor of the shape [3, 2], with all elements of 5.<jupyter_code>_X = np.full((3,2),5, dtype=int)
out = tf.convert_to_tensor(_X)
out.eval()<jupyter_output><empty_output><jupyter_text>Q6. Create a constant tensor of [[1, 3, 5], [4, 6, 8]], with dtype=float32<jupyter_code>out = tf.constant([[1, 3, 5], [4,6,8]], dtype=tf.float32)
out.eval()<jupyter_output><empty_output><jupyter_text>Q7. Create a constant tensor of the shape [2, 3], with all elements set to 4.<jupyter_code>out = tf.constant(4, shape=[2,3])
out.eval()<jupyter_output><empty_output><jupyter_text>Sequences Q8. Create a 1-D tensor of 50 evenly spaced elements between 5 and 10 inclusive.<jupyter_code>out = tf.lin_space(5., 10. , 50)
out.eval()<jupyter_output><empty_output><jupyter_text>Q9. Create a tensor which looks like [10, 12, 14, 16, ..., 100].<jupyter_code>out = tf.range(10, 101, 2)
out.eval()<jupyter_output><empty_output><jupyter_text>Random Tensors Q10. Create a random tensor of the shape [3, 2], with elements from a normal distribution of mean=0, standard deviation=2.<jupyter_code>out = tf.random_normal([3, 2], mean=0, stddev=2)
out.eval()<jupyter_output><empty_output><jupyter_text>Q11. Create a random tensor of the shape [3, 2], with elements from a normal distribution of mean=0, standard deviation=1 such that any values don't exceed 2 standard deviations from the mean.<jupyter_code>out = tf.truncated_normal([3, 2], mean=0, stddev=1)
out.eval()<jupyter_output><empty_output><jupyter_text>Q12. Create a random tensor of the shape [3, 2], with all elements from a uniform distribution that ranges from 0 to 2 (exclusive).<jupyter_code>out = tf.random_uniform([3,2], maxval=2)
out.eval()<jupyter_output><empty_output><jupyter_text>Q13. Let X be a tensor of [[1, 2], [3, 4], [5, 6]]. Shuffle X along its first dimension.<jupyter_code>out = tf.random_shuffle([[1, 2], [3, 4], [5, 6]])<jupyter_output>[[1 2]
 [5 6]
 [3 4]]
{'fraction_non_alphanumeric': 0.14781382228490833, 'fraction_numerical': 0.04710860366713681, 'mean_word_length': 6.049701789264414, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 54, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '461462', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1350, 'n_words': 382, 'path': 'gyeongchan_Constants_Sequences_and_Random_Values.ipynb', 'repo_name': 'gyeongchan-yun/tensorflow-exercises', 'size': '3545'}