From 7a928d99419a736f451f85a5f083226dd159283d Mon Sep 17 00:00:00 2001 From: jerishobed <45205454+jerishobed@users.noreply.github.com> Date: Mon, 24 Aug 2020 12:36:28 +0530 Subject: [PATCH] Assignment1 Jerish Obed --- Assignment/Assignment1 Numpy.ipynb | 199 +---------------------------- 1 file changed, 1 insertion(+), 198 deletions(-) diff --git a/Assignment/Assignment1 Numpy.ipynb b/Assignment/Assignment1 Numpy.ipynb index 32d4ebd..89f1f0f 100644 --- a/Assignment/Assignment1 Numpy.ipynb +++ b/Assignment/Assignment1 Numpy.ipynb @@ -1,198 +1 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Assignment" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Import numpy as np" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Make a python list => \\[1,2,3,4,5\\]\n", - "\n", - "Convert it into numpy array and print it" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Make a python matrix (3 x 3) => \\[[1,2,3],[4,5,6],[7,8,9]\\]\n", - "\n", - "Convert it into numpy array and print it" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Make a matrix (3 x 3) using built-in methods (like arange(), reshape() etc.):\n", - "\n", - "\\[ [1,3,5],\n", - "\n", - " [7,9,11],\n", - " \n", - " [13,15,17] \\]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create a numpy array with 10 random numbers from 0 to 10 (there should be few numbers greater than 1)" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create numpy array => \\[1,2,3,4,5\\] and convert it to 2D array with 5 rows" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Print the shape of the above created array" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create a numpy array with 10 elements in it. Access and print its 3rd, 4th and 9th element." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Print alternate elements of that array" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Change last 3 elements into 100 using broadcasting and print" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create a 5 x 5 matrix (fill it with any element you like), print it.\n", - "\n", - "Then print the middle (3 x 3) matrix." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.1" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} +{"nbformat":4,"nbformat_minor":0,"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.1"},"colab":{"name":"Assignment1 Numpy.ipynb","provenance":[],"collapsed_sections":[]}},"cells":[{"cell_type":"markdown","metadata":{"id":"b5vERLmtGlEF","colab_type":"text"},"source":["# Assignment"]},{"cell_type":"markdown","metadata":{"id":"LtCLBhh9GlEG","colab_type":"text"},"source":["Import numpy as np"]},{"cell_type":"code","metadata":{"id":"b3WXWsjqGlEI","colab_type":"code","colab":{},"executionInfo":{"status":"ok","timestamp":1598249712305,"user_tz":-330,"elapsed":3620,"user":{"displayName":"jerish btech","photoUrl":"","userId":"03464165660565966452"}}},"source":["import numpy as np"],"execution_count":1,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"iEYGAXQ-GlES","colab_type":"text"},"source":["Make a python list => \\[1,2,3,4,5\\]\n","\n","Convert it into numpy array and print it"]},{"cell_type":"code","metadata":{"id":"0clPrreyGlEU","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":34},"executionInfo":{"status":"ok","timestamp":1598249834736,"user_tz":-330,"elapsed":1474,"user":{"displayName":"jerish btech","photoUrl":"","userId":"03464165660565966452"}},"outputId":"3ca02b02-2a76-40f6-cbec-467d86ee75e0"},"source":["listpy=[1,2,3,4,5]\n","listnum=np.array(listpy)\n","listnum"],"execution_count":2,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([1, 2, 3, 4, 5])"]},"metadata":{"tags":[]},"execution_count":2}]},{"cell_type":"markdown","metadata":{"id":"6P07f_tGGlEY","colab_type":"text"},"source":["Make a python matrix (3 x 3) => \\[[1,2,3],[4,5,6],[7,8,9]\\]\n","\n","Convert it into numpy array and print it"]},{"cell_type":"code","metadata":{"id":"V3T-BmPMGlEY","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":67},"executionInfo":{"status":"ok","timestamp":1598250068168,"user_tz":-330,"elapsed":976,"user":{"displayName":"jerish btech","photoUrl":"","userId":"03464165660565966452"}},"outputId":"c576b367-4fe3-4ba3-8a7f-dadf61d56e30"},"source":["pymat=[[1,2,3],[4,5,6],[7,8,9]]\n","pynum=np.array(pymat)\n","pynum"],"execution_count":3,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([[1, 2, 3],\n"," [4, 5, 6],\n"," [7, 8, 9]])"]},"metadata":{"tags":[]},"execution_count":3}]},{"cell_type":"markdown","metadata":{"id":"qpnbvJhdGlEe","colab_type":"text"},"source":["Make a matrix (3 x 3) using built-in methods (like arange(), reshape() etc.):\n","\n","\\[ [1,3,5],\n","\n"," [7,9,11],\n"," \n"," [13,15,17] \\]"]},{"cell_type":"code","metadata":{"id":"BGv8EnS0GlEi","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":67},"executionInfo":{"status":"ok","timestamp":1598250270055,"user_tz":-330,"elapsed":4520,"user":{"displayName":"jerish btech","photoUrl":"","userId":"03464165660565966452"}},"outputId":"9a92f485-7969-461a-b07b-f54300d5a048"},"source":["mat=np.arange(1,18,2).reshape(3,3)\n","mat"],"execution_count":9,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([[ 1, 3, 5],\n"," [ 7, 9, 11],\n"," [13, 15, 17]])"]},"metadata":{"tags":[]},"execution_count":9}]},{"cell_type":"markdown","metadata":{"id":"1HgE0ldJGlEm","colab_type":"text"},"source":["Create a numpy array with 10 random numbers from 0 to 10 (there should be few numbers greater than 1)"]},{"cell_type":"code","metadata":{"id":"N6YgbcWLGlEn","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":50},"executionInfo":{"status":"ok","timestamp":1598250426898,"user_tz":-330,"elapsed":1278,"user":{"displayName":"jerish btech","photoUrl":"","userId":"03464165660565966452"}},"outputId":"8c712209-5beb-4280-826e-2af30df0f641"},"source":["np.random.randn(10)+1"],"execution_count":14,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([ 1.77633176, 2.50925711, 3.55943156, 0.91876551, -0.18709484,\n"," 1.27803193, -0.7621064 , 0.99914437, 1.78802993, 2.45935986])"]},"metadata":{"tags":[]},"execution_count":14}]},{"cell_type":"markdown","metadata":{"id":"7IewAijFGlEp","colab_type":"text"},"source":["Create numpy array => \\[1,2,3,4,5\\] and convert it to 2D array with 5 rows"]},{"cell_type":"code","metadata":{"id":"NHm89t-hGlEq","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":101},"executionInfo":{"status":"ok","timestamp":1598250581392,"user_tz":-330,"elapsed":1574,"user":{"displayName":"jerish btech","photoUrl":"","userId":"03464165660565966452"}},"outputId":"43f9c2c8-891c-4f97-8220-5d89c3cf2beb"},"source":["num=np.arange(1,6).reshape(5,1)\n","num"],"execution_count":22,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([[1],\n"," [2],\n"," [3],\n"," [4],\n"," [5]])"]},"metadata":{"tags":[]},"execution_count":22}]},{"cell_type":"markdown","metadata":{"id":"PeOzxhUaGlE0","colab_type":"text"},"source":["Print the shape of the above created array"]},{"cell_type":"code","metadata":{"id":"KxyT4mjLGlE1","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":34},"executionInfo":{"status":"ok","timestamp":1598250636013,"user_tz":-330,"elapsed":1383,"user":{"displayName":"jerish btech","photoUrl":"","userId":"03464165660565966452"}},"outputId":"a2e7f4b0-6fbf-4b8d-d137-2463e4143d69"},"source":["num.shape"],"execution_count":24,"outputs":[{"output_type":"execute_result","data":{"text/plain":["(5, 1)"]},"metadata":{"tags":[]},"execution_count":24}]},{"cell_type":"markdown","metadata":{"id":"jLDEWODcGlE4","colab_type":"text"},"source":["Create a numpy array with 10 elements in it. Access and print its 3rd, 4th and 9th element."]},{"cell_type":"code","metadata":{"id":"baWJirf0GlE5","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":34},"executionInfo":{"status":"ok","timestamp":1598251536630,"user_tz":-330,"elapsed":1441,"user":{"displayName":"jerish btech","photoUrl":"","userId":"03464165660565966452"}},"outputId":"b55cd267-a502-4ce8-d1fd-ad1c5776aece"},"source":["num1=np.arange(1,11)\n","num1[2],num1[3],num1[8]"],"execution_count":47,"outputs":[{"output_type":"execute_result","data":{"text/plain":["(3, 4, 9)"]},"metadata":{"tags":[]},"execution_count":47}]},{"cell_type":"markdown","metadata":{"id":"vaCywl8KGlE9","colab_type":"text"},"source":["Print alternate elements of that array"]},{"cell_type":"code","metadata":{"id":"ed0wvsLVGlFA","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":34},"executionInfo":{"status":"ok","timestamp":1598251575322,"user_tz":-330,"elapsed":1290,"user":{"displayName":"jerish btech","photoUrl":"","userId":"03464165660565966452"}},"outputId":"b5dca4a3-b122-4e49-b7e8-952cd54548cb"},"source":["num1[2],num1[3],num1[8] = [2,5,7]\n","num1"],"execution_count":49,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([ 1, 2, 2, 5, 5, 6, 7, 8, 7, 10])"]},"metadata":{"tags":[]},"execution_count":49}]},{"cell_type":"markdown","metadata":{"id":"NxVxPD_nGlFG","colab_type":"text"},"source":["Change last 3 elements into 100 using broadcasting and print"]},{"cell_type":"code","metadata":{"id":"iKmq33OpGlFH","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":34},"executionInfo":{"status":"ok","timestamp":1598251653882,"user_tz":-330,"elapsed":1618,"user":{"displayName":"jerish btech","photoUrl":"","userId":"03464165660565966452"}},"outputId":"f30bca62-38d8-4940-f5bd-5b99c2cd22f0"},"source":["num1[7:]=[100]\n","num1"],"execution_count":54,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([ 1, 2, 2, 5, 5, 6, 7, 100, 100, 100])"]},"metadata":{"tags":[]},"execution_count":54}]},{"cell_type":"markdown","metadata":{"id":"AE9kFBFGGlFL","colab_type":"text"},"source":["Create a 5 x 5 matrix (fill it with any element you like), print it.\n","\n","Then print the middle (3 x 3) matrix."]},{"cell_type":"code","metadata":{"id":"bXER5vn4GlFM","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":67},"executionInfo":{"status":"ok","timestamp":1598252633634,"user_tz":-330,"elapsed":1623,"user":{"displayName":"jerish btech","photoUrl":"","userId":"03464165660565966452"}},"outputId":"57edb48c-6055-4f03-f01b-2c49013dafe7"},"source":["mat1=np.arange(1,26).reshape(5,5)\n","mat1[1:4,1:4]\n","#mat1"],"execution_count":63,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([[ 7, 8, 9],\n"," [12, 13, 14],\n"," [17, 18, 19]])"]},"metadata":{"tags":[]},"execution_count":63}]}]} \ No newline at end of file