Created
September 1, 2022 04:27
-
-
Save dsaint31x/88ec4f787feba7df702c89b0cb6fd9ae to your computer and use it in GitHub Desktop.
LA_Ch01_01_Ex.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"provenance": [], | |
"authorship_tag": "ABX9TyPXQu60G8eoCGKjQCmk0O1z", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/dsaint31x/88ec4f787feba7df702c89b0cb6fd9ae/la_ch01_01_ex.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 23, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "eVLYwK6zE2Gl", | |
"outputId": "7529e4c3-3f3d-4154-ab4b-ba633788d36b" | |
}, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"<tf.Tensor: shape=(3, 1), dtype=float64, numpy=\n", | |
"array([[29.],\n", | |
" [16.],\n", | |
" [ 3.]])>" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 23 | |
} | |
], | |
"source": [ | |
"import tensorflow as tf\n", | |
"import numpy as np\n", | |
"\n", | |
"A = np.array([\n", | |
" [1 ,-2, 1],\n", | |
" [0 , 2,-8],\n", | |
" [-4, 5, 9]\n", | |
"], dtype=float)\n", | |
"\n", | |
"cmtx = tf.constant(A)\n", | |
"\n", | |
"b = np.array([0,8,-9],dtype=float)\n", | |
"\n", | |
"# tf.constant 를 이용. (1)\n", | |
"# b = b.reshape(-1,1)\n", | |
"# bvec = tf.constant(b)\n", | |
"\n", | |
"# tf.constant 를 이용. (2)\n", | |
"bvec = tf.constant(b, shape=(3,1))\n", | |
"\n", | |
"# tf.Varialbe을 이용.\n", | |
"# b = b.reshape(-1,1)\n", | |
"# bvec = tf.Variable(b, shape=(3,1))\n", | |
"\n", | |
"solution = tf.linalg.solve(cmtx,bvec)\n", | |
"solution" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"bvec.shape" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "jBGbf72LGAuJ", | |
"outputId": "c14967a0-7697-4bd0-af35-0bfc4cd23a22" | |
}, | |
"execution_count": 17, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"TensorShape([3, 1])" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 17 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"A.shape" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "ENpsjTOGGPWQ", | |
"outputId": "e024dde2-54c8-44ed-e219-6d229af6c7bd" | |
}, | |
"execution_count": 18, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"(3, 3)" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 18 | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment