LUNAR
🌙
Dashboard
Browse
SW08_Notes
JUPYTER
View Source
{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Scope" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]]\n" ] } ], "source": [ "import numpy as np\n", "\n", "PI = np.pi\n", "\n", "def create_aray(n,m)->np.ndarray:\n", " \"\"\"\n", " Creare an empty array of size (n x m) and return it\n", "\n", " Parameters:\n", " m (int): Width of array\n", " n (int): Heigh of array\n", "\n", " Returns:\n", " arr (np.ndarray) 2D numpy array \n", " \"\"\"\n", " \n", " arr = np.zeros((n,m))\n", " return arr\n", "\n", "print(create_aray(3,3))\n", " " ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[ 1 2 3 4 5 6 7 8 9 10]\n", " [ 11 12 13 14 15 16 17 18 19 20]\n", " [ 21 22 23 24 25 26 27 28 29 30]\n", " [ 31 32 33 34 35 36 37 38 39 40]\n", " [ 41 42 43 44 45 46 47 48 49 50]\n", " [ 51 52 53 54 55 56 57 58 59 60]\n", " [ 61 62 63 64 65 66 67 68 69 70]\n", " [ 71 72 73 74 75 76 77 78 79 80]\n", " [ 81 82 83 84 85 86 87 88 89 90]\n", " [ 91 92 93 94 95 96 97 98 99 100]]\n" ] } ], "source": [ "print(np.arange(1,101).reshape((10,10)))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## JSON files" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'Age': 21, 'Facutly': 'EESE'}\n" ] } ], "source": [ "import json\n", "\n", "my_dict={}\n", "my_dict[\"Matteo\"]={\"Age\":21, \"Facutly\":\"EESE\"}\n", "my_dict[\"Michi\"]={\"Age\": 23, \"Faculty\": \"Cacone\"}\n", "\n", "print(my_dict[\"Matteo\"])" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "file = \"henlo.json\"\n", "with open(file, mode=\"w+\") as fp:\n", " json.dumps(obj=my_dict)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[ 0. 50. 100.]\n" ] } ], "source": [ "import numpy as np\n", "print(np.linspace(0,100,3))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 2 }