1+ {
2+ "nbformat" : 4 ,
3+ "nbformat_minor" : 0 ,
4+ "metadata" : {
5+ "colab" : {
6+ "provenance" : [],
7+ "authorship_tag" : " ABX9TyO0fxb6omsPqcaelthdhOlo" ,
8+ "include_colab_link" : true
9+ },
10+ "kernelspec" : {
11+ "name" : " python3" ,
12+ "display_name" : " Python 3"
13+ },
14+ "language_info" : {
15+ "name" : " python"
16+ }
17+ },
18+ "cells" : [
19+ {
20+ "cell_type" : " markdown" ,
21+ "metadata" : {
22+ "id" : " view-in-github" ,
23+ "colab_type" : " text"
24+ },
25+ "source" : [
26+ " <a href=\" https://colab.research.google.com/github/iamanolive/code-harbor-hub/blob/main/tensorflow-tutorials/introduction.ipynb\" target=\" _parent\" ><img src=\" https://colab.research.google.com/assets/colab-badge.svg\" alt=\" Open In Colab\" /></a>"
27+ ]
28+ },
29+ {
30+ "cell_type" : " code" ,
31+ "source" : [
32+ " import tensorflow as tf"
33+ ],
34+ "metadata" : {
35+ "id" : " A2iC7nlsQ_tU"
36+ },
37+ "execution_count" : 8 ,
38+ "outputs" : []
39+ },
40+ {
41+ "cell_type" : " markdown" ,
42+ "source" : [
43+ " # creating tensors"
44+ ],
45+ "metadata" : {
46+ "id" : " d3SLZ6TiR4Zw"
47+ }
48+ },
49+ {
50+ "cell_type" : " code" ,
51+ "source" : [
52+ " string = tf.Variable(\" this is a string\" , tf.string)\n " ,
53+ " number = tf.Variable(324, tf.int16)\n " ,
54+ " floating = tf.Variable(3.567, tf.float64)"
55+ ],
56+ "metadata" : {
57+ "id" : " nW0NfMdPVmDo"
58+ },
59+ "execution_count" : 9 ,
60+ "outputs" : []
61+ },
62+ {
63+ "cell_type" : " markdown" ,
64+ "source" : [
65+ " # ranks or degrees of tensors"
66+ ],
67+ "metadata" : {
68+ "id" : " njzcqxqsWDpc"
69+ }
70+ },
71+ {
72+ "cell_type" : " code" ,
73+ "source" : [
74+ " rank1_tensor = tf.Variable([\" Test\" , \" Ok\" , \" Somebody\" , \" Somebody\" ], tf.string)\n " ,
75+ " rank2_tensor = tf.Variable([[\" test\" , \" ok\" ], [\" test\" , \" yes\" ], [\" ok\" , \" ok\" ]], tf.string)"
76+ ],
77+ "metadata" : {
78+ "id" : " jY_yrAmUVxmp"
79+ },
80+ "execution_count" : 27 ,
81+ "outputs" : []
82+ },
83+ {
84+ "cell_type" : " code" ,
85+ "source" : [
86+ " tf.rank(rank1_tensor)"
87+ ],
88+ "metadata" : {
89+ "colab" : {
90+ "base_uri" : " https://localhost:8080/"
91+ },
92+ "id" : " JKhqMx7iWe7x" ,
93+ "outputId" : " 7f11b444-016e-4654-8436-6340e612def7"
94+ },
95+ "execution_count" : 28 ,
96+ "outputs" : [
97+ {
98+ "output_type" : " execute_result" ,
99+ "data" : {
100+ "text/plain" : [
101+ " <tf.Tensor: shape=(), dtype=int32, numpy=1>"
102+ ]
103+ },
104+ "metadata" : {},
105+ "execution_count" : 28
106+ }
107+ ]
108+ },
109+ {
110+ "cell_type" : " code" ,
111+ "source" : [
112+ " tf.rank(rank2_tensor)"
113+ ],
114+ "metadata" : {
115+ "colab" : {
116+ "base_uri" : " https://localhost:8080/"
117+ },
118+ "id" : " sw5Ns_2YWsEo" ,
119+ "outputId" : " e96a3e35-d3b6-4056-e327-ca08c35c2795"
120+ },
121+ "execution_count" : 29 ,
122+ "outputs" : [
123+ {
124+ "output_type" : " execute_result" ,
125+ "data" : {
126+ "text/plain" : [
127+ " <tf.Tensor: shape=(), dtype=int32, numpy=2>"
128+ ]
129+ },
130+ "metadata" : {},
131+ "execution_count" : 29
132+ }
133+ ]
134+ },
135+ {
136+ "cell_type" : " code" ,
137+ "source" : [
138+ " tf.rank(number)"
139+ ],
140+ "metadata" : {
141+ "colab" : {
142+ "base_uri" : " https://localhost:8080/"
143+ },
144+ "id" : " 4qSdqk-aXRO1" ,
145+ "outputId" : " 41573023-fe3c-44a9-8f15-4e119d58fec3"
146+ },
147+ "execution_count" : 30 ,
148+ "outputs" : [
149+ {
150+ "output_type" : " execute_result" ,
151+ "data" : {
152+ "text/plain" : [
153+ " <tf.Tensor: shape=(), dtype=int32, numpy=0>"
154+ ]
155+ },
156+ "metadata" : {},
157+ "execution_count" : 30
158+ }
159+ ]
160+ },
161+ {
162+ "cell_type" : " markdown" ,
163+ "source" : [
164+ " # shapes of tensors"
165+ ],
166+ "metadata" : {
167+ "id" : " JSh-sGGtXFbd"
168+ }
169+ },
170+ {
171+ "cell_type" : " code" ,
172+ "source" : [
173+ " rank1_tensor.shape"
174+ ],
175+ "metadata" : {
176+ "colab" : {
177+ "base_uri" : " https://localhost:8080/"
178+ },
179+ "id" : " lKeKVZ0DXXXo" ,
180+ "outputId" : " 9bdef519-f5b6-42fd-af37-93f0d86f51f8"
181+ },
182+ "execution_count" : 31 ,
183+ "outputs" : [
184+ {
185+ "output_type" : " execute_result" ,
186+ "data" : {
187+ "text/plain" : [
188+ " TensorShape([4])"
189+ ]
190+ },
191+ "metadata" : {},
192+ "execution_count" : 31
193+ }
194+ ]
195+ },
196+ {
197+ "cell_type" : " code" ,
198+ "source" : [
199+ " rank2_tensor.shape"
200+ ],
201+ "metadata" : {
202+ "colab" : {
203+ "base_uri" : " https://localhost:8080/"
204+ },
205+ "id" : " Nq55Y62_XH2C" ,
206+ "outputId" : " d662fd43-8d3a-4ad5-e894-67e3e5d34557"
207+ },
208+ "execution_count" : 32 ,
209+ "outputs" : [
210+ {
211+ "output_type" : " execute_result" ,
212+ "data" : {
213+ "text/plain" : [
214+ " TensorShape([3, 2])"
215+ ]
216+ },
217+ "metadata" : {},
218+ "execution_count" : 32
219+ }
220+ ]
221+ },
222+ {
223+ "cell_type" : " markdown" ,
224+ "source" : [
225+ " # changing shapes"
226+ ],
227+ "metadata" : {
228+ "id" : " fZq-ciAuX9nd"
229+ }
230+ },
231+ {
232+ "cell_type" : " code" ,
233+ "source" : [
234+ " tensor1 = tf.ones([1, 2, 3])\n " ,
235+ " tensor2 = tf.reshape(tensor1, [2, 3, 1])\n " ,
236+ " tensor3 = tf.reshape(tensor2, [3, -1])"
237+ ],
238+ "metadata" : {
239+ "id" : " 6B220CYWYA-r"
240+ },
241+ "execution_count" : 37 ,
242+ "outputs" : []
243+ },
244+ {
245+ "cell_type" : " code" ,
246+ "source" : [
247+ " print(tensor1)"
248+ ],
249+ "metadata" : {
250+ "colab" : {
251+ "base_uri" : " https://localhost:8080/"
252+ },
253+ "id" : " yk7p22RyYS2I" ,
254+ "outputId" : " c5d3f951-7ba4-4f10-f76f-508d7efadbff"
255+ },
256+ "execution_count" : 38 ,
257+ "outputs" : [
258+ {
259+ "output_type" : " stream" ,
260+ "name" : " stdout" ,
261+ "text" : [
262+ " tf.Tensor(\n " ,
263+ " [[[1. 1. 1.]\n " ,
264+ " [1. 1. 1.]]], shape=(1, 2, 3), dtype=float32)\n "
265+ ]
266+ }
267+ ]
268+ },
269+ {
270+ "cell_type" : " code" ,
271+ "source" : [
272+ " print(tensor2)"
273+ ],
274+ "metadata" : {
275+ "colab" : {
276+ "base_uri" : " https://localhost:8080/"
277+ },
278+ "id" : " 121lHMJYYVG3" ,
279+ "outputId" : " 0b1d5684-ce45-4f6d-a108-1a54ba008f6d"
280+ },
281+ "execution_count" : 39 ,
282+ "outputs" : [
283+ {
284+ "output_type" : " stream" ,
285+ "name" : " stdout" ,
286+ "text" : [
287+ " tf.Tensor(\n " ,
288+ " [[[1.]\n " ,
289+ " [1.]\n " ,
290+ " [1.]]\n " ,
291+ " \n " ,
292+ " [[1.]\n " ,
293+ " [1.]\n " ,
294+ " [1.]]], shape=(2, 3, 1), dtype=float32)\n "
295+ ]
296+ }
297+ ]
298+ },
299+ {
300+ "cell_type" : " code" ,
301+ "source" : [
302+ " print(tensor3)"
303+ ],
304+ "metadata" : {
305+ "colab" : {
306+ "base_uri" : " https://localhost:8080/"
307+ },
308+ "id" : " UnbSuXgxYWiw" ,
309+ "outputId" : " 9c1f3139-6863-47a9-f95b-067fc158a914"
310+ },
311+ "execution_count" : 44 ,
312+ "outputs" : [
313+ {
314+ "output_type" : " stream" ,
315+ "name" : " stdout" ,
316+ "text" : [
317+ " tf.Tensor(\n " ,
318+ " [[1. 1.]\n " ,
319+ " [1. 1.]\n " ,
320+ " [1. 1.]], shape=(3, 2), dtype=float32)\n "
321+ ]
322+ }
323+ ]
324+ }
325+ ]
326+ }
0 commit comments