Created
October 14, 2022 10:36
-
-
Save mscroggs/f26c9aac2be076525966f9010823695a to your computer and use it in GitHub Desktop.
lecture1.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": "ABX9TyPxXFdKmucjS6jzW8kHpK64", | |
"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/mscroggs/f26c9aac2be076525966f9010823695a/lecture1.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "8mZXL_cPvdO9", | |
"outputId": "dfba6b3b-453c-4e2c-d512-22f5a6a0f4be" | |
}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Hello World\n" | |
] | |
} | |
], | |
"source": [ | |
"print(\"Hello World\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"import numpy as np" | |
], | |
"metadata": { | |
"id": "RVB8Ob4JvjEY" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"a = np.array([1, 2.5, 6])\n", | |
"matrix = np.array([[1, 0], [0, 1]])" | |
], | |
"metadata": { | |
"id": "_kCfD4lYv0Tx" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"a" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "TkiK_Osqv_pE", | |
"outputId": "74644e17-f99c-4772-8c22-689d66c720fc" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"array([1. , 2.5, 6. ])" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 5 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"b = np.array([1, 2.5, 6], dtype=\"float32\")" | |
], | |
"metadata": { | |
"id": "_DIgCZFdwApS" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"b" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "GjCk0temwLhr", | |
"outputId": "a7df6ae3-49b8-4c64-c340-4a410905df2e" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"array([1. , 2.5, 6. ], dtype=float32)" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 7 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"a_random = np.random.rand(5)\n", | |
"a_ones = np.ones(3)\n", | |
"a_zeros = np.zeros((3, 3))\n", | |
"a_empty = np.empty(10, dtype=\"int64\")\n", | |
"a_range = np.arange(4, 10)" | |
], | |
"metadata": { | |
"id": "1s8e54qawMVb" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"print(a_random)\n", | |
"print(a_ones)\n", | |
"print(a_range)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "dep0tBLCwack", | |
"outputId": "64b4b306-80e3-4caa-c348-d7737f1c894b" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"[[0.34228755 0.19983794 0.57252219]\n", | |
" [0.19210979 0.17529747 0.20346028]\n", | |
" [0.54568769 0.67577675 0.39756324]]\n", | |
"[1. 1. 1.]\n", | |
"[4 5 6 7 8 9]\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"a_random @ a_ones" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "dsGFv7snwbZM", | |
"outputId": "0f55a97f-2112-49cb-9efd-bfd16d20c4e1" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"array([1.27680211, 1.93109138, 0.90798191])" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 16 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"print(a_random)\n", | |
"print(a_random[1:3])\n", | |
"print(a_random[0:5:2])" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "Od0KRINxws1A", | |
"outputId": "0146bebd-7bd0-4fb0-ff43-7187af48d519" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"[0.60128865 0.5510969 0.48542947 0.11672078 0.1401818 ]\n", | |
"[0.5510969 0.48542947]\n", | |
"[0.60128865 0.48542947 0.1401818 ]\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"matrix = np.random.rand(5,5)" | |
], | |
"metadata": { | |
"id": "gjBGhtohxwoh" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"print(matrix)\n", | |
"print(matrix[1,2:4])" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "fBgZ47Gayc7m", | |
"outputId": "c23ffe0b-4823-443b-9958-d729fea063dd" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"[[0.59106915 0.95922431 0.18003074 0.29132311 0.39444247]\n", | |
" [0.3066083 0.21008175 0.25499676 0.60436743 0.83227058]\n", | |
" [0.62174497 0.46483412 0.93826309 0.26653236 0.60751204]\n", | |
" [0.43323311 0.50835979 0.08424809 0.66042097 0.88675662]\n", | |
" [0.39922824 0.88350175 0.55648825 0.30047552 0.26408969]]\n", | |
"[0.25499676 0.60436743]\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"matrix[0,0] = 1\n", | |
"print(matrix)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "PTHfx9ciyi0i", | |
"outputId": "32497be2-96e9-415c-deb1-308ee71ab5e6" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"[[1. 0.95922431 0.18003074 0.29132311 0.39444247]\n", | |
" [0.3066083 0.21008175 0.25499676 0.60436743 0.83227058]\n", | |
" [0.62174497 0.46483412 0.93826309 0.26653236 0.60751204]\n", | |
" [0.43323311 0.50835979 0.08424809 0.66042097 0.88675662]\n", | |
" [0.39922824 0.88350175 0.55648825 0.30047552 0.26408969]]\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [], | |
"metadata": { | |
"id": "WWJZIEWoy1sr" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment