From 2c77520cb3cf23746afc35516438b68a36d1e1e0 Mon Sep 17 00:00:00 2001 From: Said Gourida <33969482+Said113@users.noreply.github.com> Date: Fri, 19 Oct 2018 22:16:39 +0100 Subject: [PATCH 1/2] Created using Colaboratory --- Numpy/exercises.ipynb | 156 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 Numpy/exercises.ipynb diff --git a/Numpy/exercises.ipynb b/Numpy/exercises.ipynb new file mode 100644 index 0000000..7e1441e --- /dev/null +++ b/Numpy/exercises.ipynb @@ -0,0 +1,156 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "exercises.ipynb", + "version": "0.3.2", + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "[View in Colaboratory](https://colab.research.google.com/github/Said113/Machine-Learning/blob/master/Numpy/exercises.ipynb)" + ] + }, + { + "metadata": { + "id": "jTlLW6CdyQKo", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "# **NumPy Exercises for Data Analysis**" + ] + }, + { + "metadata": { + "id": "Fc-F34DryPjY", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "### 1. Import numpy as np and see the version ?" + ] + }, + { + "metadata": { + "id": "2FROXdSeykQo", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "import numpy as np\n", + "#np.version this just for show numpy Path \n", + "np.version.version" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "3gUCcUm_yrgf", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "### 2. How to create a 1D array?" + ] + }, + { + "metadata": { + "id": "kWkYCtoZykTE", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "#here you can solve this problem with many solutions\n", + "a=np.array([1,2,3,4,5]) #here you can pass any sequence like(tuble,list,dict,set)\n", + "b=np.arange(5)\n", + "c=np.array(range(1,6))\n", + "e=np.ones(5,\"int\")\n", + "f=np.zeros(5,dtype=\"int8\")\n", + "j=np.random.choice(2,5)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "n5DnkuMsy_Tm", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "### 3. How to create a boolean array?\n", + "##### Q Create a 3×3 numpy array of all True’s !!" + ] + }, + { + "metadata": { + "id": "xsyqlkpaykSV", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "a=np.ones(9,dtype='bool').reshape(3,3)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "FPpLU-YtzTp9", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "### 4 Extract all odd numbers from arr ?\n", + "##### arr=np.array([1,2,3,4,5,6,7,8,9])" + ] + }, + { + "metadata": { + "id": "FoLZzUi4zUBk", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "arr=np.array([1,2,3,4,5,6,7,8,9])\n", + "a=arr[::2]\n", + "b=arr[arr%2!=0]\n", + "c=np.where(arr%2!=0) #this statement if you want to know the positions of the elements" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "F7h9cfSB2h_8", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file From 3024b3b5a32490e0b49e73fcf1e148ded3c872df Mon Sep 17 00:00:00 2001 From: Said Gourida <33969482+Said113@users.noreply.github.com> Date: Fri, 19 Oct 2018 22:41:28 +0100 Subject: [PATCH 2/2] add q 5 --- exercises.ipynb | 217 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 exercises.ipynb diff --git a/exercises.ipynb b/exercises.ipynb new file mode 100644 index 0000000..1ad941f --- /dev/null +++ b/exercises.ipynb @@ -0,0 +1,217 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "exercises.ipynb", + "version": "0.3.2", + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "[View in Colaboratory](https://colab.research.google.com/github/Said113/Machine-Learning/blob/ex_said/exercises.ipynb)" + ] + }, + { + "metadata": { + "id": "jTlLW6CdyQKo", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "# **NumPy Exercises for Data Analysis**" + ] + }, + { + "metadata": { + "id": "Fc-F34DryPjY", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "### 1. Import numpy as np and see the version ?" + ] + }, + { + "metadata": { + "id": "2FROXdSeykQo", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "9f89af6f-d785-45b4-df9a-784f268be604" + }, + "cell_type": "code", + "source": [ + "import numpy as np\n", + "#np.version this just for show numpy Path \n", + "np.version.version" + ], + "execution_count": 2, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'1.14.6'" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 2 + } + ] + }, + { + "metadata": { + "id": "3gUCcUm_yrgf", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "### 2. How to create a 1D array?" + ] + }, + { + "metadata": { + "id": "kWkYCtoZykTE", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "#here you can solve this problem with many solutions\n", + "a=np.array([1,2,3,4,5]) #here you can pass any sequence like(tuble,list,dict,set)\n", + "b=np.arange(5)\n", + "c=np.array(range(1,6))\n", + "e=np.ones(5,\"int\")\n", + "f=np.zeros(5,dtype=\"int8\")\n", + "j=np.random.choice(2,5)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "n5DnkuMsy_Tm", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "### 3. How to create a boolean array?\n", + "##### Q Create a 3×3 numpy array of all True’s !!" + ] + }, + { + "metadata": { + "id": "xsyqlkpaykSV", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "a=np.ones(9,dtype='bool').reshape(3,3)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "FPpLU-YtzTp9", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "### 4 Extract all odd numbers from arr ?\n", + "##### arr=np.array([1,2,3,4,5,6,7,8,9])" + ] + }, + { + "metadata": { + "id": "FoLZzUi4zUBk", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "arr=np.array([1,2,3,4,5,6,7,8,9])\n", + "a=arr[::2]\n", + "b=arr[arr%2!=0]\n", + "c=np.where(arr%2!=0) #this statement if you want to know the positions of the elements" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "jsnIR8CcC23h", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "### 5 How to replace items that satisfy a condition with another value in numpy array?\n", + "###### Q. Replace all odd numbers in arr with -1 " + ] + }, + { + "metadata": { + "id": "F7h9cfSB2h_8", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "a1b20d98-c2d3-421f-e8d9-c51a0c578df5" + }, + "cell_type": "code", + "source": [ + "arr=np.array([1,2,3,4,5,6,7,8,9])\n", + "c=np.where(arr%2!=0)\n", + "arr[c]=-1\n", + "arr" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([-1, 2, -1, 4, -1, 6, -1, 8, -1])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 3 + } + ] + }, + { + "metadata": { + "id": "J5NNN_PMDgEM", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file