diff --git a/10_Random_sampling.ipynb b/10_Random_sampling.ipynb index b3fc88f..9ce8516 100644 --- a/10_Random_sampling.ipynb +++ b/10_Random_sampling.ipynb @@ -1,301 +1,419 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Random Sampling" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "import numpy as np" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "'1.11.2'" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "np.__version__" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "__author__ = 'kyubyong. longinglove@nate.com'" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Simple random data" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q1. Create an array of shape (3, 2) and populate it with random samples from a uniform distribution over [0, 1)." - ] - }, - { - "cell_type": "code", - "execution_count": 49, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[ 0.13879034, 0.71300174],\n", - " [ 0.08121322, 0.00393554],\n", - " [ 0.02349471, 0.56677474]])" - ] - }, - "execution_count": 49, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q2. Create an array of shape (1000, 1000) and populate it with random samples from a standard normal distribution. And verify that the mean and standard deviation is close enough to 0 and 1 repectively." - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-0.00110028519551\n", - "0.999683483393\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q3. Create an array of shape (3, 2) and populate it with random integers ranging from 0 to 3 (inclusive) from a discrete uniform distribution." - ] - }, - { - "cell_type": "code", - "execution_count": 44, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[1, 3],\n", - " [3, 0],\n", - " [0, 0]])" - ] - }, - "execution_count": 44, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q4. Extract 1 elements from x randomly such that each of them would be associated with probabilities .3, .5, .2. Then print the result 10 times." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "5 out of 10\n", - "2 out of 10\n", - "3 out of 10\n", - "5 out of 10\n", - "2 out of 10\n", - "5 out of 10\n", - "2 out of 10\n", - "2 out of 10\n", - "2 out of 10\n", - "5 out of 10\n" - ] - } - ], - "source": [ - "x = [b'3 out of 10', b'5 out of 10', b'2 out of 10']\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q5. Extract 3 different integers from 0 to 9 randomly with the same probabilities." - ] - }, - { - "cell_type": "code", - "execution_count": 66, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([5, 4, 0])" - ] - }, - "execution_count": 66, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Permutations" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q6. Shuffle numbers between 0 and 9 (inclusive)." - ] - }, - { - "cell_type": "code", - "execution_count": 86, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2 3 8 4 5 1 0 6 9 7]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 88, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[5 2 7 4 1 0 6 8 9 3]\n" - ] - } - ], - "source": [ - "# Or\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Random generator" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q7. Assign number 10 to the seed of the random generator so that you can get the same value next time." - ] - }, - { - "cell_type": "code", - "execution_count": 91, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 2", - "language": "python", - "name": "python2" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.10" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "3UDDkN1hTEKQ" + }, + "source": [ + "# Random Sampling" + ] + }, + { + "cell_type": "markdown", + "source": [], + "metadata": { + "id": "aSKOlci4T2N8" + } + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true, + "id": "MV0iM2fXTEKR" + }, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "xlXhykXZTEKS", + "outputId": "3b543690-093a-4cb9-b199-d90962f14885", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'1.25.2'" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 2 + } + ], + "source": [ + "np.__version__" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "id": "qpr7mb4kTEKS" + }, + "outputs": [], + "source": [ + "__author__ = 'kyubyong. longinglove@nate.com'" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "StDpKS5rTEKS" + }, + "source": [ + "## Simple random data" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "438LHI7wTEKS" + }, + "source": [ + "Q1. Create an array of shape (3, 2) and populate it with random samples from a uniform distribution over [0, 1)." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "id": "2jgJ8bfxTEKT", + "outputId": "19209aa1-d2cb-4853-b21f-cd26f6bcbefc", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[0.44973262, 0.20192478],\n", + " [0.88800608, 0.50218322],\n", + " [0.16239423, 0.57113706]])" + ] + }, + "metadata": {}, + "execution_count": 4 + } + ], + "source": [ + "np.random.rand(3, 2)\n", + "# Or np.random.random((3,2))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "UULK_Qg6TEKT" + }, + "source": [ + "Q2. Create an array of shape (1000, 1000) and populate it with random samples from a standard normal distribution. And verify that the mean and standard deviation is close enough to 0 and 1 repectively." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "id": "iH0crU22TEKT", + "outputId": "82771d61-fdf0-4cb2-a9fa-c7371952469c", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "-0.0022732807185111437\n", + "1.0005348176435038\n" + ] + } + ], + "source": [ + "out1 = np.random.randn(1000, 1000)\n", + "out2 = np.random.standard_normal((1000, 1000))\n", + "out3 = np.random.normal(loc=0.0, scale=1.0, size=(1000, 1000))\n", + "assert np.allclose(np.mean(out1), np.mean(out2), atol=0.1)\n", + "assert np.allclose(np.mean(out1), np.mean(out3), atol=0.1)\n", + "assert np.allclose(np.std(out1), np.std(out2), atol=0.1)\n", + "assert np.allclose(np.std(out1), np.std(out3), atol=0.1)\n", + "print (np.mean(out3))\n", + "print (np.std(out1))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "X63lz-iWTEKT" + }, + "source": [ + "Q3. Create an array of shape (3, 2) and populate it with random integers ranging from 0 to 3 (inclusive) from a discrete uniform distribution." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "id": "O0_TtaDiTEKT", + "outputId": "ca70f24a-6d5c-48f7-d953-d2651fea24ff", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1, 0],\n", + " [3, 3],\n", + " [2, 0]])" + ] + }, + "metadata": {}, + "execution_count": 6 + } + ], + "source": [ + "np.random.randint(0, 4, (3, 2))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Su5AzWiWTEKT" + }, + "source": [ + "Q4. Extract 1 elements from x randomly such that each of them would be associated with probabilities .3, .5, .2. Then print the result 10 times." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": true, + "id": "O_io_w9UTEKT" + }, + "outputs": [], + "source": [ + "x = [b'3 out of 10', b'5 out of 10', b'2 out of 10']" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "PLdinAZBTEKT", + "outputId": "9a6eb038-0d46-425e-a81d-2e7d87f1573e", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "b'3 out of 10'\n", + "b'3 out of 10'\n", + "b'5 out of 10'\n", + "b'3 out of 10'\n", + "b'5 out of 10'\n", + "b'3 out of 10'\n", + "b'3 out of 10'\n", + "b'3 out of 10'\n", + "b'3 out of 10'\n", + "b'5 out of 10'\n" + ] + } + ], + "source": [ + "for _ in range(10):\n", + " print (np.random.choice(x, p=[.3, .5, .2]))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "8DvK_TVLTEKU" + }, + "source": [ + "Q5. Extract 3 different integers from 0 to 9 randomly with the same probabilities." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "id": "OOi-L3wLTEKU", + "outputId": "6b4fe959-a2b3-4afa-9cc4-dcfb84ebe1e9", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([6, 3, 5])" + ] + }, + "metadata": {}, + "execution_count": 9 + } + ], + "source": [ + "np.random.choice(10, 3, replace=False)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "fGsBAULfTEKU" + }, + "source": [ + "## Permutations" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7QPzXLXWTEKU" + }, + "source": [ + "Q6. Shuffle numbers between 0 and 9 (inclusive)." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "id": "vOSkQ5ctTEKU", + "outputId": "b3c61a66-09f8-42f8-8cf4-795293726722", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[2 1 4 3 5 6 0 8 9 7]\n" + ] + } + ], + "source": [ + "x = np.arange(10)\n", + "np.random.shuffle(x)\n", + "print (x)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "id": "hQikPcZCTEKU", + "outputId": "bbefc485-49a0-43bd-bef9-88a8826e634c", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[3 5 6 9 2 4 0 1 8 7]\n" + ] + } + ], + "source": [ + "# Or\n", + "print (np.random.permutation(10))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "b4uy8WTETEKU" + }, + "source": [ + "## Random generator" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "AZwnSthyTEKU" + }, + "source": [ + "Q7. Assign number 10 to the seed of the random generator so that you can get the same value next time." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": true, + "id": "XVgU0imGTEKU" + }, + "outputs": [], + "source": [ + "np.random.seed(10)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.10" + }, + "colab": { + "provenance": [], + "include_colab_link": true + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file diff --git a/12_Sorting_searching_and_counting.ipynb b/12_Sorting_searching_and_counting.ipynb index bbdda65..1149767 100644 --- a/12_Sorting_searching_and_counting.ipynb +++ b/12_Sorting_searching_and_counting.ipynb @@ -1,444 +1,585 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Soring, searching, and counting" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "import numpy as np" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "'1.11.2'" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "np.__version__" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "author = 'kyubyong. longinglove@nate.com'" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Sorting" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q1. Sort x along the second axis." - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[1 4]\n", - " [1 3]]\n" - ] - } - ], - "source": [ - "x = np.array([[1,4],[3,1]])\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q2. Sort pairs of surnames and first names and return their indices. (first by surname, then by name)." - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1 2 0]\n" - ] - } - ], - "source": [ - "surnames = ('Hertz', 'Galilei', 'Hertz')\n", - "first_names = ('Heinrich', 'Galileo', 'Gustav')\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q3. Get the indices that would sort x along the second axis." - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[0 1]\n", - " [1 0]]\n" - ] - } - ], - "source": [ - "x = np.array([[1,4],[3,1]])\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q4. Create an array such that its fifth element would be the same as the element of sorted x, and it divide other elements by their value." - ] - }, - { - "cell_type": "code", - "execution_count": 48, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "x = [5 1 6 3 9 8 2 7 4 0]\n", - "\n", - "Check the fifth element of this new array is 5, the first four elements are all smaller than 5, and 6th through the end are bigger than 5\n", - "[2 0 4 3 1 5 8 7 6 9]\n" - ] - } - ], - "source": [ - "x = np.random.permutation(10)\n", - "print \"x =\", x\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q5. Create the indices of an array such that its third element would be the same as the element of sorted x, and it divide other elements by their value." - ] - }, - { - "cell_type": "code", - "execution_count": 56, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "x = [2 8 3 7 5 6 4 0 9 1]\n", - "partitioned = [0 1 2 3 4 5 8 6 9 7]\n", - "indices = [0 1 2 3 4 5 8 6 9 7]\n" - ] - } - ], - "source": [ - "x = np.random.permutation(10)\n", - "print \"x =\", x\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Searching" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q6. Get the maximum and minimum values and their indices of x along the second axis." - ] - }, - { - "cell_type": "code", - "execution_count": 78, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "x = [[0 5 9 8 2]\n", - " [3 7 4 1 6]]\n", - "maximum values = [9 7]\n", - "max indices = [2 1]\n", - "minimum values = [0 1]\n", - "min indices = [0 3]\n" - ] - } - ], - "source": [ - "x = np.random.permutation(10).reshape(2, 5)\n", - "print \"x =\", x\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q7. Get the maximum and minimum values and their indices of x along the second axis, ignoring NaNs." - ] - }, - { - "cell_type": "code", - "execution_count": 79, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "maximum values ignoring NaNs = [ 4. 3.]\n", - "max indices = [1 0]\n", - "minimum values ignoring NaNs = [ 4. 2.]\n", - "min indices = [1 1]\n" - ] - } - ], - "source": [ - "x = np.array([[np.nan, 4], [3, 2]])\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q8. Get the values and indices of the elements that are bigger than 2 in x.\n" - ] - }, - { - "cell_type": "code", - "execution_count": 113, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Values bigger than 2 = [3 3 5]\n", - "Their indices are (array([0, 1, 1], dtype=int64), array([2, 1, 2], dtype=int64))\n" - ] - } - ], - "source": [ - "x = np.array([[1, 2, 3], [1, 3, 5]])\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q9. Get the indices of the elements that are bigger than 2 in the flattend x." - ] - }, - { - "cell_type": "code", - "execution_count": 100, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[0 1 2 3 4 5]\n" - ] - } - ], - "source": [ - "x = np.array([[1, 2, 3], [1, 3, 5]])\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q10. Check the elements of x and return 0 if it is less than 0, otherwise the element itself." - ] - }, - { - "cell_type": "code", - "execution_count": 105, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[0 0 0]\n", - " [0 0 0]\n", - " [1 2 3]]\n" - ] - } - ], - "source": [ - "x = np.arange(-5, 4).reshape(3, 3)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q11. Get the indices where elements of y should be inserted to x to maintain order." - ] - }, - { - "cell_type": "code", - "execution_count": 109, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([0, 2, 1, 3], dtype=int64)" - ] - }, - "execution_count": 109, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x = [1, 3, 5, 7, 9]\n", - "y = [0, 4, 2, 6]\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Counting" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q12. Get the number of nonzero elements in x." - ] - }, - { - "cell_type": "code", - "execution_count": 120, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "5\n" - ] - } - ], - "source": [ - "x = [[0,1,7,0,0],[3,0,0,2,19]]\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 2", - "language": "python", - "name": "python2" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.10" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "d40ozj1nUO1B" + }, + "source": [ + "# Soring, searching, and counting" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "id": "5RZBdgSYUO1C" + }, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "id": "miR79Z_GUO1D", + "outputId": "ad7dabaa-ce68-4524-8187-93965d83c8d9", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'1.25.2'" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 10 + } + ], + "source": [ + "np.__version__" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": true, + "id": "bCyOimyAUO1E" + }, + "outputs": [], + "source": [ + "author = 'kyubyong. longinglove@nate.com'" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "u0mXnkMEUO1E" + }, + "source": [ + "## Sorting" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "1Et9DMSXUO1E" + }, + "source": [ + "Q1. Sort x along the second axis." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "id": "KmWQaTnAUO1E", + "outputId": "9a32fe7d-ee3d-4be7-8d8a-51dcf4594fcd", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[1 4]\n", + " [1 3]]\n" + ] + } + ], + "source": [ + "x = np.array([[1,4],[3,1]])\n", + "out = np.sort(x, axis=1)\n", + "x.sort(axis=1)\n", + "assert np.array_equal(out, x)\n", + "print (out)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "MGRLgY8rUO1E" + }, + "source": [ + "Q2. Sort pairs of surnames and first names and return their indices. (first by surname, then by name)." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "id": "NP781l5OUO1E", + "outputId": "606b15d1-f470-43ce-ba74-f46e47a947f1", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[1 2 0]\n" + ] + } + ], + "source": [ + "surnames = ('Hertz', 'Galilei', 'Hertz')\n", + "first_names = ('Heinrich', 'Galileo', 'Gustav')\n", + "print (np.lexsort((first_names, surnames)))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ZYX_0-g5UO1E" + }, + "source": [ + "Q3. Get the indices that would sort x along the second axis." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "id": "v8RoX0vgUO1E", + "outputId": "5a4a6a26-f462-4442-d062-249ad05ac966", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[0 1]\n", + " [1 0]]\n" + ] + } + ], + "source": [ + "x = np.array([[1,4],[3,1]])\n", + "out = np.argsort(x, axis=1)\n", + "print (out)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "OyKb0aomUO1F" + }, + "source": [ + "Q4. Create an array such that its fifth element would be the same as the element of sorted x, and it divide other elements by their value." + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "id": "ZQoeKKftUO1F", + "outputId": "ca41f57f-209f-496f-88ef-47fc9b92ddfb", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "x = [8 0 2 6 4 9 3 5 7 1]\n", + "\n", + "Check the fifth element of this new array is 5, the first four elements are all smaller than 5, and 6th through the end are bigger than 5\n", + "\n", + "[0 1 2 3 4 5 6 7 8 9]\n" + ] + } + ], + "source": [ + "x = np.random.permutation(10)\n", + "print (\"x =\", x)\n", + "print (\"\\nCheck the fifth element of this new array is 5, the first four elements are all smaller than 5, and 6th through the end are bigger than 5\\n\")\n", + "out = np.partition(x, 5)\n", + "x.partition(5) # in-place equivalent\n", + "assert np.array_equal(x, out)\n", + "print (out)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "HXu91CQEUO1F" + }, + "source": [ + "Q5. Create the indices of an array such that its third element would be the same as the element of sorted x, and it divide other elements by their value." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "id": "zJy7giZ8UO1F", + "outputId": "19ba1067-b491-4a9c-dcac-d418eee06245", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "x = [8 1 4 9 0 3 2 5 7 6]\n", + "partitioned = [1 2 0 3 5 4 6 9 7 8]\n", + "indices = [1 2 0 3 5 4 6 9 7 8]\n" + ] + } + ], + "source": [ + "x = np.random.permutation(10)\n", + "print (\"x =\", x)\n", + "partitioned = np.partition(x, 3)\n", + "indices = np.argpartition(x, 3)\n", + "print (\"partitioned =\", partitioned)\n", + "print (\"indices =\", partitioned)\n", + "assert np.array_equiv(x[indices], partitioned)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "xBoIeHcqUO1F" + }, + "source": [ + "## Searching" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "-N81qZP4UO1F" + }, + "source": [ + "Q6. Get the maximum and minimum values and their indices of x along the second axis." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "id": "qi8fIo3DUO1F", + "outputId": "3a1f9543-8a03-4cec-cc96-b4ebc0215257", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "x = [[4 1 3 5 7]\n", + " [6 8 0 9 2]]\n", + "maximum values = [7 9]\n", + "max indices = [4 3]\n", + "minimum values = [1 0]\n", + "min indices = [1 2]\n" + ] + } + ], + "source": [ + "x = np.random.permutation(10).reshape(2, 5)\n", + "print (\"x =\", x)\n", + "print (\"maximum values =\", np.max(x, 1))\n", + "print (\"max indices =\", np.argmax(x, 1))\n", + "print (\"minimum values =\", np.min(x, 1))\n", + "print (\"min indices =\", np.argmin(x, 1))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "vA5ewD44UO1F" + }, + "source": [ + "Q7. Get the maximum and minimum values and their indices of x along the second axis, ignoring NaNs." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "id": "C5nSbXnKUO1F", + "outputId": "088bdc38-d492-4f1f-eda7-984c11a5b618", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "maximum values ignoring NaNs = [4. 3.]\n", + "max indices = [1 0]\n", + "minimum values ignoring NaNs = [4. 2.]\n", + "min indices = [1 1]\n" + ] + } + ], + "source": [ + "x = np.array([[np.nan, 4], [3, 2]])\n", + "print (\"maximum values ignoring NaNs =\", np.nanmax(x, 1))\n", + "print (\"max indices =\", np.nanargmax(x, 1))\n", + "print (\"minimum values ignoring NaNs =\", np.nanmin(x, 1))\n", + "print (\"min indices =\", np.nanargmin(x, 1))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Ydj_yENFUO1F" + }, + "source": [ + "Q8. Get the values and indices of the elements that are bigger than 2 in x.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "id": "j6dL4g3EUO1F", + "outputId": "f08eea4f-6c31-42e0-bafa-eff2d1100906", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Values bigger than 2 = [3 3 5]\n", + "Their indices are (array([0, 1, 1]), array([2, 1, 2]))\n" + ] + } + ], + "source": [ + "x = np.array([[1, 2, 3], [1, 3, 5]])\n", + "print (\"Values bigger than 2 =\", x[x>2])\n", + "print (\"Their indices are \", np.nonzero(x > 2))\n", + "assert np.array_equiv(x[x>2], x[np.nonzero(x > 2)])\n", + "assert np.array_equiv(x[x>2], np.extract(x > 2, x))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "1klOlA0CUO1G" + }, + "source": [ + "Q9. Get the indices of the elements that are bigger than 2 in the flattend x." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "scrolled": true, + "id": "_l9pNH-tUO1G", + "outputId": "26dc41fe-3b35-4115-f96a-993b512ef927", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[2 4 5]\n" + ] + } + ], + "source": [ + "x = np.array([[1, 2, 3], [1, 3, 5]])\n", + "print (np.flatnonzero(x>2))\n", + "assert np.array_equiv(np.flatnonzero(x), x.ravel().nonzero())" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5g1tUU71UO1G" + }, + "source": [ + "Q10. Check the elements of x and return 0 if it is less than 0, otherwise the element itself." + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "id": "sc95qheEUO1G", + "outputId": "f8ae5346-df48-4983-8871-1d01684554cf", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[0 0 0]\n", + " [0 0 0]\n", + " [1 2 3]]\n" + ] + } + ], + "source": [ + "x = np.arange(-5, 4).reshape(3, 3)\n", + "print (np.where(x <0, 0, x))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "0ZWwG-LaUO1G" + }, + "source": [ + "Q11. Get the indices where elements of y should be inserted to x to maintain order." + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "id": "bukmJRHKUO1G", + "outputId": "d13ddc0e-381f-4412-c07e-388ffe8b7172", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([0, 2, 1, 3])" + ] + }, + "metadata": {}, + "execution_count": 22 + } + ], + "source": [ + "x = [1, 3, 5, 7, 9]\n", + "y = [0, 4, 2, 6]\n", + "np.searchsorted(x, y)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "HroFrh6BUO1G" + }, + "source": [ + "## Counting" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5gKmeyw0UO1G" + }, + "source": [ + "Q12. Get the number of nonzero elements in x." + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "id": "2xPjEAauUO1G", + "outputId": "cf451ff0-8e42-4790-e59b-b0af1d863404", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "5\n" + ] + } + ], + "source": [ + "x = [[0,1,7,0,0],[3,0,0,2,19]]\n", + "print (np.count_nonzero(x))\n", + "assert np.count_nonzero(x) == len(x[x!=0])" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": true, + "id": "vB98uHFxUO1G" + }, + "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.5.2" + }, + "colab": { + "provenance": [], + "include_colab_link": true + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file diff --git a/13_Statistics.ipynb b/13_Statistics.ipynb index b5cb14a..f80fcd3 100644 --- a/13_Statistics.ipynb +++ b/13_Statistics.ipynb @@ -1,579 +1,743 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Statistics" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "__author__ = \"kyubyong. kbpark.linguist@gmail.com\"" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "import numpy as np" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "'1.11.3'" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "np.__version__" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Order statistics" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q1. Return the minimum value of x along the second axis." - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "x=\n", - " [[0 1]\n", - " [2 3]]\n", - "ans=\n", - " [0 2]\n" - ] - } - ], - "source": [ - "x = np.arange(4).reshape((2, 2))\n", - "print(\"x=\\n\", x)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q2. Return the maximum value of x along the second axis. Reduce the second axis to the dimension with size one." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "x=\n", - " [[0 1]\n", - " [2 3]]\n", - "ans=\n", - " [[1]\n", - " [3]]\n" - ] - } - ], - "source": [ - "x = np.arange(4).reshape((2, 2))\n", - "print(\"x=\\n\", x)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q3. Calcuate the difference between the maximum and the minimum of x along the second axis." - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "x=\n", - " [[0 1 2 3 4]\n", - " [5 6 7 8 9]]\n", - "ans=\n", - " [4 4]\n" - ] - } - ], - "source": [ - "x = np.arange(10).reshape((2, 5))\n", - "print(\"x=\\n\", x)\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q4. Compute the 75th percentile of x along the second axis." - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "x=\n", - " [[ 1 2 3 4 5]\n", - " [ 6 7 8 9 10]]\n", - "ans=\n", - " [ 4. 9.]\n" - ] - } - ], - "source": [ - "x = np.arange(1, 11).reshape((2, 5))\n", - "print(\"x=\\n\", x)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Averages and variances" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q5. Compute the median of flattened x." - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "x=\n", - " [[1 2 3]\n", - " [4 5 6]\n", - " [7 8 9]]\n", - "ans=\n", - " 5.0\n" - ] - } - ], - "source": [ - "x = np.arange(1, 10).reshape((3, 3))\n", - "print(\"x=\\n\", x)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q6. Compute the weighted average of x." - ] - }, - { - "cell_type": "code", - "execution_count": 62, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2.66666666667\n" - ] - } - ], - "source": [ - "x = np.arange(5)\n", - "weights = np.arange(1, 6)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q7. Compute the mean, standard deviation, and variance of x along the second axis." - ] - }, - { - "cell_type": "code", - "execution_count": 72, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "x=\n", - " [0 1 2 3 4]\n", - "mean=\n", - " 2.0\n", - "std=\n", - " 1.41421356237\n", - "variance=\n", - " 2.0\n" - ] - } - ], - "source": [ - "x = np.arange(5)\n", - "print(\"x=\\n\",x)\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Correlating" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q8. Compute the covariance matrix of x and y." - ] - }, - { - "cell_type": "code", - "execution_count": 82, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ans=\n", - " [[ 1. -1.]\n", - " [-1. 1.]]\n" - ] - } - ], - "source": [ - "x = np.array([0, 1, 2])\n", - "y = np.array([2, 1, 0])\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q9. In the above covariance matrix, what does the -1 mean?" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q10. Compute Pearson product-moment correlation coefficients of x and y." - ] - }, - { - "cell_type": "code", - "execution_count": 87, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ans=\n", - " [[ 1. 0.92857143]\n", - " [ 0.92857143 1. ]]\n" - ] - } - ], - "source": [ - "x = np.array([0, 1, 3])\n", - "y = np.array([2, 4, 5])\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q11. Compute cross-correlation of x and y." - ] - }, - { - "cell_type": "code", - "execution_count": 90, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ans=\n", - " [19]\n" - ] - } - ], - "source": [ - "x = np.array([0, 1, 3])\n", - "y = np.array([2, 4, 5])\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Histograms" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q12. Compute the histogram of x against the bins." - ] - }, - { - "cell_type": "code", - "execution_count": 105, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ans=\n", - " (array([2, 3, 1], dtype=int64), array([0, 1, 2, 3]))\n" - ] - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAgsAAAFkCAYAAACuFXjcAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAFVpJREFUeJzt3X+s5WWdH/D3h+XHKCljUsoMNKRUVlmsKbMzbhURB8sP\nF0wwq2Z3b6XOojUiJksnbd2Yhmy6TSWE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CcctGQWKh6rqqaq6o6refmh7ethb93NtGcy1V3tdRt+Af9ypY7692sGM\nWWKuvaKqjqqq383oXkeL3ehwRebZtA9D9B5EtXmRNt0HUa1s99asScbt6YweFPH+JO/LaNfV3VW1\n5VB18ghgrk3GXJtjfFfbzya5t7X23U5V821swJiZa0mq6s1V9ZMkLyW5MclvtdYeXaT6isyztfog\nKZaptbYnyZ45RfdX1elJdiZZNydRceiZa7/kxiRvSnLOanfkMHJQY2auveLRjM4/2JjRHZFvrap3\ndgLDsk17z8K0HkR1pJlk3BbyQJJfXalOHYHMtZWzLudaVX0+ySVJzmutPb1EdfMtg8dsIeturrXW\nftFae6y19q3W2r/O6IT3qxapviLzbKphobX28yQHHkSV5FUPolrsoRf3za0/1n0Q1ZFmwnFbyJaM\nduOxsHU/11bQuptr4196703yrtba9w+iybqfbxOM2ULW3VxbwFFJFjuksDLzbBXO2vztJC8k+VCS\nX0vyhYzO5Pw749evSXLLnPqnJflJRmd0npHR5Vz/N8kFq30G6hoft6uSXJrk9CT/IKPjgT/PKL2v\n+s8zpTE7PqNddVsyOsv6n4/XTzXXVnTczLXRbvT/ndHlgJvmLBvm1Pm0+bbsMTPXRmNybpK/l+TN\n4/+Pv0jyj8evH5LPtdX6Ya9M8kSSn2WUbt4y57U/TfKNefXfmdE3658l+Z9J/ulq/4Ot9XFL8q/G\nY/XTJM9ldCXFO1f7Z5jyeG0f/7LbP2/5E3Nt5cbNXHvlEtP547U/yYfm1DHfljlm5lpLkpuTPDae\nM88kueNAUDiU88yDpACALs+GAAC6hAUAoEtYAAC6hAUAoEtYAAC6hAUAoEtYAAC6hAUAoEtYAAC6\nhAUAoEtYAAC6/h+sRyodSeNw6wAAAABJRU5ErkJggg==\n", - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "x = np.array([0.5, 0.7, 1.0, 1.2, 1.3, 2.1])\n", - "bins = np.array([0, 1, 2, 3])\n", - "print(\"ans=\\n\", ...)\n", - "\n", - "import matplotlib.pyplot as plt\n", - "%matplotlib inline\n", - "plt.hist(x, bins=bins)\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q13. Compute the 2d histogram of x and y." - ] - }, - { - "cell_type": "code", - "execution_count": 127, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ans=\n", - " [[ 3. 0. 0. 0.]\n", - " [ 0. 2. 0. 0.]\n", - " [ 0. 0. 1. 1.]]\n" - ] - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAhcAAAFkCAYAAACThxm6AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3X2wHXd95/n3NzLgyLWAZhx8yawVL9aDPXnA2CG2cLDN\nWEie66rDEKhobCNA8lI8yI5XVCQqVVsrm6rFSB4gRDYhBVpCRuHYqd1ZQWFHUgQxlAo8bHwxbCWI\nIwk88gK2EXJBNhezifjtH+fI3Afdh/65+57u2+9X1Snu6dN97rc/p+X75XT/fh0pJSRJksryS8Mu\nQJIkLS42F5IkqVQ2F5IkqVQ2F5IkqVQ2F5IkqVQ2F5IkqVQ2F5IkqVQ2F5IkqVQ2F5IkqVQ2F5Ik\nqVSVNhcR8a6I+EZE/Hjw+EpE3DDL+tdGxM+nPE5HxMuqrFOSJJXnnIrf/wngfcBRIIC3A5+NiMtS\nSt+aYZsErAL+8bkFKT1dcZ2SJKkksdA3LouIHwF/mFL61Fleuxb4IrAspfSTBS1MkiSVYsGuuYiI\nX4qI/wgsBb4626rAYxHx/Yg4GBGvWZgKJUlSGao+LUJE/Ab9ZuJc+qc63phSOjLD6j8A3gn8HfAi\n4B3AwxHxOymlx2Z4/38NrAceB54tt3pJkha1c4GLgAMppR+V9aaVnxaJiHOA5cBLgDfTbxiumaXB\nmLr9w8B/Sym9bYbXbwb+spxqJUlqpVtSSp8p680q/+YipfQvwHcGT78eEb8D3AG8e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GA//a/InqV/euVPz/zRWKyPwT+kx4Gf0u/Uf3vCa58Cvjhl/Wvo/7/3nwJHgY3D3oc6\nZwZsG+T0T8AP6Y80uWbY+7DAeV07+ON4esrjf/M4Ky83j7XnhuxOzeu5/857vJWTWVnHmjcukyRJ\nparNNReSJGlxsLmQJEmlsrmQJEmlsrmQJEmlsrmQJEmlsrmQJEmlsrmQJEmlsrmQJEmlsrmQJEml\nsrmQJEmlsrmQJEml+v8Bev3xcJRJzrUAAAAASUVORK5CYII=\n", - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "xedges = [0, 1, 2, 3]\n", - "yedges = [0, 1, 2, 3, 4]\n", - "x = np.array([0, 0.1, 0.2, 1., 1.1, 2., 2.1])\n", - "y = np.array([0, 0.1, 0.2, 1., 1.1, 2., 3.3])\n", - "...\n", - "\n", - "plt.scatter(x, y)\n", - "plt.grid()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q14. Count number of occurrences of 0 through 7 in x." - ] - }, - { - "cell_type": "code", - "execution_count": 129, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ans=\n", - " [1 3 1 1 0 0 0 1]\n" - ] + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "neMWZTOiV9eP" + }, + "source": [ + "# Statistics" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true, + "id": "MOVdfXuJV9eQ" + }, + "outputs": [], + "source": [ + "__author__ = \"kyubyong. kbpark.linguist@gmail.com\"" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true, + "id": "s9Uy9Z9SV9eR" + }, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "id": "SfrdAsOiV9eR", + "outputId": "794aac59-f3ca-46eb-b977-383dcae441dd", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'1.25.2'" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 3 + } + ], + "source": [ + "np.__version__" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "lKbr1lPfV9eR" + }, + "source": [ + "## Order statistics" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Zjrpa58QV9eR" + }, + "source": [ + "Q1. Return the minimum value of x along the second axis." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "id": "Jbqz-b2CV9eR", + "outputId": "9820696a-382d-47de-94b6-5986198f7b9d", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "x=\n", + " [[0 1]\n", + " [2 3]]\n", + "ans=\n", + " [0 2]\n" + ] + } + ], + "source": [ + "x = np.arange(4).reshape((2, 2))\n", + "print(\"x=\\n\", x)\n", + "print(\"ans=\\n\", np.amin(x, 1))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ruBraKn-V9eS" + }, + "source": [ + "Q2. Return the maximum value of x along the second axis. Reduce the second axis to the dimension with size one." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "id": "PxmDvcy4V9eS", + "outputId": "ee2ebb99-d177-49ef-c9b2-29a8e660890a", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "x=\n", + " [[0 1]\n", + " [2 3]]\n", + "ans=\n", + " [[1]\n", + " [3]]\n" + ] + } + ], + "source": [ + "x = np.arange(4).reshape((2, 2))\n", + "print(\"x=\\n\", x)\n", + "print(\"ans=\\n\", np.amax(x, 1, keepdims=True))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "BuJdKN8pV9eS" + }, + "source": [ + "Q3. Calcuate the difference between the maximum and the minimum of x along the second axis." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "id": "cIyNeLR3V9eS", + "outputId": "d43c93ca-65e6-4767-a563-ba432001d550", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "x=\n", + " [[0 1 2 3 4]\n", + " [5 6 7 8 9]]\n", + "ans=\n", + " [4 4]\n" + ] + } + ], + "source": [ + "x = np.arange(10).reshape((2, 5))\n", + "print(\"x=\\n\", x)\n", + "\n", + "out1 = np.ptp(x, 1)\n", + "out2 = np.amax(x, 1) - np.amin(x, 1)\n", + "assert np.allclose(out1, out2)\n", + "print(\"ans=\\n\", out1)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "WxdfsuhaV9eS" + }, + "source": [ + "Q4. Compute the 75th percentile of x along the second axis." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "id": "f9apWkVbV9eS", + "outputId": "e75e5b56-d298-43dd-aa88-a4d776089951", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "x=\n", + " [[ 1 2 3 4 5]\n", + " [ 6 7 8 9 10]]\n", + "ans=\n", + " [4. 9.]\n" + ] + } + ], + "source": [ + "x = np.arange(1, 11).reshape((2, 5))\n", + "print(\"x=\\n\", x)\n", + "\n", + "print(\"ans=\\n\", np.percentile(x, 75, 1))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "R-iQvsB8V9eS" + }, + "source": [ + "## Averages and variances" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "HRoI3eoRV9eS" + }, + "source": [ + "Q5. Compute the median of flattened x." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "H8du7M2qV9eS", + "outputId": "8ea933c5-7eb3-427a-ba76-e049c86c5b9b", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "x=\n", + " [[1 2 3]\n", + " [4 5 6]\n", + " [7 8 9]]\n", + "ans=\n", + " 5.0\n" + ] + } + ], + "source": [ + "x = np.arange(1, 10).reshape((3, 3))\n", + "print(\"x=\\n\", x)\n", + "\n", + "print(\"ans=\\n\", np.median(x))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "MRXmGKSnV9eS" + }, + "source": [ + "Q6. Compute the weighted average of x." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "id": "WhPX2iHMV9eS", + "outputId": "16f1a50b-1e23-4a86-f09d-0a77926e740e", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "2.6666666666666665\n" + ] + } + ], + "source": [ + "x = np.arange(5)\n", + "weights = np.arange(1, 6)\n", + "\n", + "out1 = np.average(x, weights=weights)\n", + "out2 = (x*(weights/weights.sum())).sum()\n", + "assert np.allclose(out1, out2)\n", + "print(out1)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "EBWXE-L1V9eT" + }, + "source": [ + "Q7. Compute the mean, standard deviation, and variance of x along the second axis." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "id": "6pDhG0sTV9eT", + "outputId": "ad7c58ac-0bd1-4db4-bba3-60677b07f2f1", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "x=\n", + " [0 1 2 3 4]\n", + "mean=\n", + " 2.0\n", + "std=\n", + " 1.4142135623730951\n", + "variance=\n", + " 2.0\n" + ] + } + ], + "source": [ + "x = np.arange(5)\n", + "print(\"x=\\n\",x)\n", + "\n", + "out1 = np.mean(x)\n", + "out2 = np.average(x)\n", + "assert np.allclose(out1, out2)\n", + "print(\"mean=\\n\", out1)\n", + "\n", + "out3 = np.std(x)\n", + "out4 = np.sqrt(np.mean((x - np.mean(x)) ** 2 ))\n", + "assert np.allclose(out3, out4)\n", + "print(\"std=\\n\", out3)\n", + "\n", + "out5 = np.var(x)\n", + "out6 = np.mean((x - np.mean(x)) ** 2 )\n", + "assert np.allclose(out5, out6)\n", + "print(\"variance=\\n\", out5)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "69YVjkvnV9eT" + }, + "source": [ + "## Correlating" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ey29dSRQV9eT" + }, + "source": [ + "Q8. Compute the covariance matrix of x and y." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "id": "ALsRZh7OV9eT", + "outputId": "39380b0a-5261-4c9f-f6ac-45df167c5ac8", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "ans=\n", + " [[ 1. -1.]\n", + " [-1. 1.]]\n" + ] + } + ], + "source": [ + "x = np.array([0, 1, 2])\n", + "y = np.array([2, 1, 0])\n", + "\n", + "print(\"ans=\\n\", np.cov(x, y))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "08PqEfEvV9eT" + }, + "source": [ + "Q9. In the above covariance matrix, what does the -1 mean?" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "gQbQARW6V9eT" + }, + "source": [ + "It means `x` and `y` correlate perfectly in opposite directions." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "XkZDHD5TV9eT" + }, + "source": [ + "Q10. Compute Pearson product-moment correlation coefficients of x and y." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "id": "Xj89Y1z2V9eT", + "outputId": "c6b10d2e-f0d8-4d59-eb14-1eabf593167b", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "ans=\n", + " [[1. 0.92857143]\n", + " [0.92857143 1. ]]\n" + ] + } + ], + "source": [ + "x = np.array([0, 1, 3])\n", + "y = np.array([2, 4, 5])\n", + "\n", + "print(\"ans=\\n\", np.corrcoef(x, y))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "BRXqj1zuV9eT" + }, + "source": [ + "Q11. Compute cross-correlation of x and y." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "id": "oDJp8rf5V9eU", + "outputId": "dcdc16ab-51c3-4a79-8da0-e56fd091b0be", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "ans=\n", + " [19]\n" + ] + } + ], + "source": [ + "x = np.array([0, 1, 3])\n", + "y = np.array([2, 4, 5])\n", + "\n", + "print(\"ans=\\n\", np.correlate(x, y))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "MIC8zlaSV9eU" + }, + "source": [ + "## Histograms" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "YFaPoZq1V9eU" + }, + "source": [ + "Q12. Compute the histogram of x against the bins." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "id": "5jTOJgvjV9eU", + "outputId": "07d14749-c60f-486d-9db9-114372ed00a3", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 465 + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "ans=\n", + " (array([2, 3, 1]), array([0, 1, 2, 3]))\n" + ] + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "
" + ], + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAeRklEQVR4nO3db2xV533A8Z9Jgp2o2AlLsQ04gY2OhPyxKQ1gIhXSklgMRfGbjvGisIxkawRTGNMqqKog2hfOlNGk2lhIFCVojRBpmgES+U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3rzYunVrfPOb34xvfOMb8bnPfS527NgRN9988+A+CgBg2Lrg7xm5GHzPCMORv6ZhKPhrGoaTIf+eEQCAwSBGAICkxAgAkJQYAQCSEiMAQFJiBABISowAAEmJEQAgKTECACQlRgCApMQIAJCUGAEAkhIjAEBSYgQASEqMAABJiREAICkxAgAkJUYAgKTECACQlBgBAJISIwBAUmIEAEhKjAAASYkRACApMQIAJCVGAICkxAgAkJQYAQCSEiMAQFJiBABISowAAEmJEQAgKTECACQlRgCApMQIAJCUGAEAkhIjAEBSYgQASEqMAABJiREAICkxAgAkJUYAgKTECACQlBgBAJISIwBAUmIEAEhKjAAASYkRACCpvGKkrq4ubrvtthg3blxMmDAhamtr48SJE+eds2XLligoKOixFRUVXdCiAYCRI68Y2bdvX6xcuTLeeOONqK+vjw8//DDuuuuuaG9vP++84uLiaG5u7t5Onjx5QYsGAEaOy/MZ/Morr/T4ecuWLTFhwoQ4dOhQfPGLX+xzXkFBQZSVlQ1shQDAiHZB14y0tbVFRMT48ePPO+7cuXNx/fXXR0VFRdxzzz1x/Pjx847v6OiIXC7XYwMARqYBx0hXV1esXr06br/99rj55pv7HDd9+vR4+umnY+fOnfHss89GV1dXzJs3L955550+59TV1UVJSUn3VlFRMdBlAgCXuIIsy7KBTHzggQfi5Zdfjv3798fkyZP7Pe/DDz+MG2+8MZYuXRrf/va3ex3T0dERHR0d3T/ncrmoqKiItra2KC4uHshy4aKbsvbF1EtgBPrFw4tTLwH6LZfLRUlJyae+f+d1zcjHVq1aFbt27YrXXnstrxCJiLjiiiti5syZ8dZbb/U5prCwMAoLCweyNABgmMnrY5osy2LVqlWxffv22LNnT0ydOjXvO+zs7IyjR49GeXl53nMBgJEnrzMjK1eujK1bt8bOnTtj3Lhx0dLSEhERJSUlceWVV0ZExLJly2LSpElRV1cXERHf+ta3Yu7cuTFt2rT49a9/HY888kicPHky7rvvvkF+KADAcJRXjDz++OMREbFgwYIe+5955pn467/+64iIOHXqVIwZ8/sTLu+//37cf//90dLSEtdcc03MmjUrDhw4EDNmzLiwlQMAI8KAL2C9mPp7AQxcSlzAylBwASvDSX/fv/1vGgAgKTECACQlRgCApMQIAJCUGAEAkhIjAEBSYgQASEqMAABJiREAICkxAgAkJUYAgKTECACQlBgBAJISIwBAUmIEAEhKjAAASYkRACApMQIAJCVGAICkxAgAkJQYAQCSEiMAQFJiBABISowAAEmJEQAgKTECACQlRgCApMQIAJCUGAEAkhIjAEBSYgQASEqMAABJiREAICkxAgAkJUYAgKTECACQlBgBAJISIwBAUmIEAEhKjAAASYkRACApMQIAJCVGAICkxAgAkJQYAQCSEiMAQFJiBABIKq8Yqauri9tuuy3GjRsXEyZMiNra2jhx4sSnznv++efjhhtuiKKiorjlllvipZdeGvCCAYCRJa8Y2bdvX6xcuTLeeOONqK+vjw8//DDuuuuuaG9v73POgQMHYunSpbFixYo4cuRI1NbWRm1tbRw7duyCFw8ADH8FWZZlA5387rvvxoQJE2Lfvn3xxS9+sdcxS5Ysifb29ti1a1f3vrlz50ZVVVVs3ry5X/eTy+WipKQk2traori4eKDLhYtqytoXUy+BEegXDy9OvQTot/6+f1/QNSNtbW0RETF+/Pg+xzQ2NsbChQt77KupqYnGxsYLuWsAYIS4fKATu7q6YvXq1XH77bfHzTff3Oe4lpaWKC0t7bGvtLQ0Wlpa+pzT0dERHR0d3T/ncrmBLhMAuMQNOEZWrlwZx44di/379w/meiLiowtlN2zYMOi32xun0gEgrQF9TLNq1arYtWtXvPrqqzF58uTzji0rK4vW1tYe+1pbW6OsrKzPOevWrYu2trbu7fTp0wNZJgAwDOQVI1mWxapVq2L79u2xZ8+emDp16qfOqa6ujoaGhh776uvro7q6us85hYWFUVxc3GMDAEamvD6mWblyZWzdujV27twZ48aN677uo6SkJK688sqIiFi2bFlMmjQp6urqIiLiwQcfjPnz58fGjRtj8eLFsW3btjh48GA8+eSTg/xQAIDhKK8zI48//ni0tbXFggULory8vHt77rnnusecOnUqmpubu3+eN29ebN26NZ588smorKyMH/zgB7Fjx47zXvQ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UmIEAEhKjAAASQ0oRjZt2hRTpkyJoqKimDNnTrz55pvnHf/888/HDTfcEEVFRXHLLbfESy+9NKDFAgAjT94x8txzz8WaNWti/fr1cfjw4aisrIyampo4c+ZMr+MPHDgQS5cujRUrVsSRI0eitrY2amtr49ixYxe8eABg+CvIsizLZ8KcOXPitttui3/7t3+LiIiurq6oqKiIv//7v4+1a9d+YvySJUuivb09du3a1b1v7ty5UVVVFZs3b+7XfeZyuSgpKYm2trYoLi7OZ7mfasraFwf19gBguPnFw4uH5Hb7+/59eT43+sEHH8ShQ4di3bp13fvGjBkTCxcujMbGxl7nNDY2xpo1a3rsq6mpiR07dvR5Px0dHdHR0dH9c1tbW0R89KAGW1fHbwb9NgFgOBmK99c/vN1PO++RV4y899570dnZGaWlpT32l5aWxk9/+tNe57S0tPQ6vqWlpc/7qauriw0bNnxif0VFRT7LBQD6oeSxob39s2fPRklJSZ+/zytGLpZ169b1OJvS1dUV//d//xd/8id/EgUFBYN2P7lcLioqKuL06dOD/vHPSONY5cfx6j/Hqv8cq/5zrPpvKI9VlmVx9uzZmDhx4nnH5RUj1157bVx22WXR2traY39ra2uUlZX1OqesrCyv8RERhYWFUVhY2GPf1Vdfnc9S81JcXOzJ2k+OVX4cr/5zrPrPseo/x6r/hupYne+MyMfy+muasWPHxqxZs6KhoaF7X1dXVzQ0NER1dXWvc6qrq3uMj4ior6/vczwAMLrk/THNmjVrYvny5fGFL3whZs+eHY899li0t7fHvffeGxERy5Yti0mTJkVdXV1ERDz44IMxf/782LhxYyxevDi2bdsWBw8ejCeffHJwHwkAMCzlHSNLliyJd999Nx566KFoaWmJqqqqeOWVV7ovUj116lSMGfP7Ey7z5s2LrVu3xje/+c34xje+EZ/73Odix44dcfPNNw/eoxigwsLCWL9+/Sc+EuKTHKv8OF7951j1n2PVf45V/10Kxyrv7xkBABhM/jcNAJCUGAEAkhIjAEBSYgQASGrEx8imTZtiypQpUVRUFHPmzIk333zzvOOff/75uOGGG6KoqChuueWWeOmlly7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HZp/97GezL3/5y90hkmWXznOqIMuybGjPvQAA9G3EXjMCAAwPYgQASEqMAABJiREAICkxAgAkJUYAgKTECACQlBgBAJISIwBAUmIEAEhKjAAASYkRACCp/wcM2ejgLIEgSQAAAABJRU5ErkJggg==\n" + }, + "metadata": {} + } + ], + "source": [ + "x = np.array([0.5, 0.7, 1.0, 1.2, 1.3, 2.1])\n", + "bins = np.array([0, 1, 2, 3])\n", + "print(\"ans=\\n\", np.histogram(x, bins))\n", + "\n", + "import matplotlib.pyplot as plt\n", + "%matplotlib inline\n", + "plt.hist(x, bins=bins)\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "MxLBx_1IV9eU" + }, + "source": [ + "Q13. Compute the 2d histogram of x and y." + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "id": "zJzFcfrxV9eU", + "outputId": "fd3f788c-3f4b-490c-d876-8519381f161d", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 499 + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "ans=\n", + " [[3. 0. 0. 0.]\n", + " [0. 2. 0. 0.]\n", + " [0. 0. 1. 1.]]\n" + ] + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "
" + ], + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAl2klEQVR4nO3dfWxU55n38d/YGWZixePWRX4hOIk3pATH4cUEJ6ZVQ1bYhkQ0/ofNEqXQNMnuIiwl61WiOsrGuGjXm6chNNpQyG6WOBtkNWUrXCWlhinUIIq9Di+WMG8qrQXdxmMXkXjAhsnIc54/kJ1M7AGfYcb3HPv7kazo3L7PmWt8MZpfzjlzj8uyLEsAAACGpJkuAAAATG2EEQAAYBRhB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/XOnHihKmnMGVcunTJOnbsmHXs2DFLkvXGG29Yx44ds86dO2dZlmX98Ic/tL73ve+NzP/jH/9oZWRkWC+++KJ16tQpa/PmzVZ6errV0tJi6ilMGXZ7tWnTJqu5udn6/e9/bx0/ftx6/vnnrbS0NOs3v/mNqacwZaxdu9bKysqyWltbrZ6enpGfwcHBkTmT9X1rUocRy7Ksf//3f7fuuOMOa9q0aVZpaanV3t4+8ruHH37YWrNmTdT8n//859Y3v/lNa9q0adZ9991n/epXv5rgiqc2O/164YUXRubm5uZajz76qHX06FEDVU89wx///OrPcH/WrFljPfzww6P2mT9/vjVt2jTrr/7qr6x33313wuueiuz26rXXXrPuvvtuy+v1WtnZ2daSJUusffv2mSl+ihmrT5KiXiuT9X3LZVmWNdFnYwAAAIZN2ntGAACAMxBGAACAUYQRAABgFGEEAAAYRRgBAABGEUYAAIBRhBEAAGAUYQQAABhFGAEAAEYRRgAAgFGEEQAAYBRhBAAAGPX/AQRQCCvzpd9yAAAAAElFTkSuQmCC\n" + }, + "metadata": {} + } + ], + "source": [ + "xedges = [0, 1, 2, 3]\n", + "yedges = [0, 1, 2, 3, 4]\n", + "x = np.array([0, 0.1, 0.2, 1., 1.1, 2., 2.1])\n", + "y = np.array([0, 0.1, 0.2, 1., 1.1, 2., 3.3])\n", + "H, xedges, yedges = np.histogram2d(x, y, bins=(xedges, yedges))\n", + "print(\"ans=\\n\", H)\n", + "\n", + "plt.scatter(x, y)\n", + "plt.grid()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "mETuEVXKV9eU" + }, + "source": [ + "Q14. Count number of occurrences of 0 through 7 in x." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "id": "oF2wKR9LV9eU", + "outputId": "a3953a0e-75eb-46f0-cff9-2dbe08eed8a5", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "ans=\n", + " [1 3 1 1 0 0 0 1]\n" + ] + } + ], + "source": [ + "x = np.array([0, 1, 1, 3, 2, 1, 7])\n", + "print(\"ans=\\n\", np.bincount(x))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "1vgmx0YqV9eU" + }, + "source": [ + "Q15. Return the indices of the bins to which each value in x belongs." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "id": "ofDrI6xIV9eU", + "outputId": "83b361ef-1b0e-4dbd-a92f-fd6c3380dab7", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "ans=\n", + " [1 4 3 2]\n" + ] + } + ], + "source": [ + "x = np.array([0.2, 6.4, 3.0, 1.6])\n", + "bins = np.array([0.0, 1.0, 2.5, 4.0, 10.0])\n", + "\n", + "print(\"ans=\\n\", np.digitize(x, bins))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": true, + "id": "LbA5_PcdV9eV" + }, + "outputs": [], + "source": [] } - ], - "source": [ - "x = np.array([0, 1, 1, 3, 2, 1, 7])\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q15. Return the indices of the bins to which each value in x belongs." - ] - }, - { - "cell_type": "code", - "execution_count": 130, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ans=\n", - " [1 4 3 2]\n" - ] + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python [conda root]", + "language": "python", + "name": "conda-root-py" + }, + "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.5.2" + }, + "colab": { + "provenance": [], + "include_colab_link": true } - ], - "source": [ - "x = np.array([0.2, 6.4, 3.0, 1.6])\n", - "bins = np.array([0.0, 1.0, 2.5, 4.0, 10.0])\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "anaconda-cloud": {}, - "kernelspec": { - "display_name": "Python [conda root]", - "language": "python", - "name": "conda-root-py" }, - "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.5.2" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file diff --git a/1_Array_creation_routines.ipynb b/1_Array_creation_routines.ipynb index 71790b6..dc472c9 100644 --- a/1_Array_creation_routines.ipynb +++ b/1_Array_creation_routines.ipynb @@ -1,798 +1,1120 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Array creation routines" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Ones and zeros" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "import numpy as np" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create a new array of 2*2 integers, without initializing entries." - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[0, 0],\n", - " [0, 0]])" - ] - }, - "execution_count": 27, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let X = np.array([1,2,3], [4,5,6], np.int32). \n", - "Create a new array with the same shape and type as X." - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[1, 2, 3],\n", - " [4, 5, 6]])" - ] - }, - "execution_count": 32, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "X = np.array([[1,2,3], [4,5,6]], np.int32)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create a 3-D array with ones on the diagonal and zeros elsewhere." - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[ 1., 0., 0.],\n", - " [ 0., 1., 0.],\n", - " [ 0., 0., 1.]])" - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[ 1., 0., 0.],\n", - " [ 0., 1., 0.],\n", - " [ 0., 0., 1.]])" - ] - }, - "execution_count": 35, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create a new array of 3*2 float numbers, filled with ones." - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[ 1., 1.],\n", - " [ 1., 1.],\n", - " [ 1., 1.]])" - ] - }, - "execution_count": 36, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let x = np.arange(4, dtype=np.int64). Create an array of ones with the same shape and type as X." - ] - }, - { - "cell_type": "code", - "execution_count": 59, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([1, 1, 1, 1], dtype=int64)" - ] - }, - "execution_count": 59, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x = np.arange(4, dtype=np.int64)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create a new array of 3*2 float numbers, filled with zeros." - ] - }, - { - "cell_type": "code", - "execution_count": 45, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[ 0., 0.],\n", - " [ 0., 0.],\n", - " [ 0., 0.]])" - ] - }, - "execution_count": 45, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let x = np.arange(4, dtype=np.int64). Create an array of zeros with the same shape and type as X." - ] - }, - { - "cell_type": "code", - "execution_count": 58, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([0, 0, 0, 0], dtype=int64)" - ] - }, - "execution_count": 58, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x = np.arange(4, dtype=np.int64)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create a new array of 2*5 uints, filled with 6." - ] - }, - { - "cell_type": "code", - "execution_count": 49, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[6, 6, 6, 6, 6],\n", - " [6, 6, 6, 6, 6]], dtype=uint32)" - ] - }, - "execution_count": 49, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let x = np.arange(4, dtype=np.int64). Create an array of 6's with the same shape and type as X." - ] - }, - { - "cell_type": "code", - "execution_count": 79, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([6, 6, 6, 6], dtype=int64)" - ] - }, - "execution_count": 79, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x = np.arange(4, dtype=np.int64)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## From existing data" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create an array of [1, 2, 3]." - ] - }, - { - "cell_type": "code", - "execution_count": 53, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([1, 2, 3])" - ] - }, - "execution_count": 53, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let x = [1, 2]. Convert it into an array." - ] - }, - { - "cell_type": "code", - "execution_count": 60, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([1, 2])" - ] - }, - "execution_count": 60, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x = [1,2]\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let X = np.array([[1, 2], [3, 4]]). Convert it into a matrix." - ] - }, - { - "cell_type": "code", - "execution_count": 62, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "matrix([[1, 2],\n", - " [3, 4]])" - ] - }, - "execution_count": 62, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "X = np.array([[1, 2], [3, 4]])\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let x = [1, 2]. Conver it into an array of `float`." - ] - }, - { - "cell_type": "code", - "execution_count": 63, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([ 1., 2.])" - ] - }, - "execution_count": 63, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x = [1, 2]\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let x = np.array([30]). Convert it into scalar of its single element, i.e. 30." - ] - }, - { - "cell_type": "code", - "execution_count": 67, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "30" - ] - }, - "execution_count": 67, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x = np.array([30])\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let x = np.array([1, 2, 3]). Create a array copy of x, which has a different id from x." - ] - }, - { - "cell_type": "code", - "execution_count": 76, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "70140352 [1 2 3]\n", - "70140752 [1 2 3]\n" - ] - } - ], - "source": [ - "x = np.array([1, 2, 3])\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Numerical ranges" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create an array of 2, 4, 6, 8, ..., 100." - ] - }, - { - "cell_type": "code", - "execution_count": 85, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26,\n", - " 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52,\n", - " 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78,\n", - " 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100])" - ] - }, - "execution_count": 85, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create a 1-D array of 50 evenly spaced elements between 3. and 10., inclusive." - ] - }, - { - "cell_type": "code", - "execution_count": 86, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([ 3. , 3.14285714, 3.28571429, 3.42857143,\n", - " 3.57142857, 3.71428571, 3.85714286, 4. ,\n", - " 4.14285714, 4.28571429, 4.42857143, 4.57142857,\n", - " 4.71428571, 4.85714286, 5. , 5.14285714,\n", - " 5.28571429, 5.42857143, 5.57142857, 5.71428571,\n", - " 5.85714286, 6. , 6.14285714, 6.28571429,\n", - " 6.42857143, 6.57142857, 6.71428571, 6.85714286,\n", - " 7. , 7.14285714, 7.28571429, 7.42857143,\n", - " 7.57142857, 7.71428571, 7.85714286, 8. ,\n", - " 8.14285714, 8.28571429, 8.42857143, 8.57142857,\n", - " 8.71428571, 8.85714286, 9. , 9.14285714,\n", - " 9.28571429, 9.42857143, 9.57142857, 9.71428571,\n", - " 9.85714286, 10. ])" - ] - }, - "execution_count": 86, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create a 1-D array of 50 element spaced evenly on a log scale between 3. and 10., exclusive." - ] - }, - { - "cell_type": "code", - "execution_count": 88, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([ 1.00000000e+03, 1.38038426e+03, 1.90546072e+03,\n", - " 2.63026799e+03, 3.63078055e+03, 5.01187234e+03,\n", - " 6.91830971e+03, 9.54992586e+03, 1.31825674e+04,\n", - " 1.81970086e+04, 2.51188643e+04, 3.46736850e+04,\n", - " 4.78630092e+04, 6.60693448e+04, 9.12010839e+04,\n", - " 1.25892541e+05, 1.73780083e+05, 2.39883292e+05,\n", - " 3.31131121e+05, 4.57088190e+05, 6.30957344e+05,\n", - " 8.70963590e+05, 1.20226443e+06, 1.65958691e+06,\n", - " 2.29086765e+06, 3.16227766e+06, 4.36515832e+06,\n", - " 6.02559586e+06, 8.31763771e+06, 1.14815362e+07,\n", - " 1.58489319e+07, 2.18776162e+07, 3.01995172e+07,\n", - " 4.16869383e+07, 5.75439937e+07, 7.94328235e+07,\n", - " 1.09647820e+08, 1.51356125e+08, 2.08929613e+08,\n", - " 2.88403150e+08, 3.98107171e+08, 5.49540874e+08,\n", - " 7.58577575e+08, 1.04712855e+09, 1.44543977e+09,\n", - " 1.99526231e+09, 2.75422870e+09, 3.80189396e+09,\n", - " 5.24807460e+09, 7.24435960e+09])" - ] - }, - "execution_count": 88, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Building matrices" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let X = np.array([[ 0, 1, 2, 3],\n", - " [ 4, 5, 6, 7],\n", - " [ 8, 9, 10, 11]]).\n", - " Get the diagonal of X, that is, [0, 5, 10]." - ] - }, - { - "cell_type": "code", - "execution_count": 93, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([ 0, 5, 10])" - ] - }, - "execution_count": 93, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "X = np.array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]])\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create a 2-D array whose diagonal equals [1, 2, 3, 4] and 0's elsewhere." - ] - }, - { - "cell_type": "code", - "execution_count": 95, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[1, 0, 0, 0],\n", - " [0, 2, 0, 0],\n", - " [0, 0, 3, 0],\n", - " [0, 0, 0, 4]])" - ] - }, - "execution_count": 95, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create an array which looks like below.\n", - "array([[ 0., 0., 0., 0., 0.],\n", - " [ 1., 0., 0., 0., 0.],\n", - " [ 1., 1., 0., 0., 0.]])" - ] - }, - { - "cell_type": "code", - "execution_count": 97, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[ 0., 0., 0., 0., 0.],\n", - " [ 1., 0., 0., 0., 0.],\n", - " [ 1., 1., 0., 0., 0.]])" - ] - }, - "execution_count": 97, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create an array which looks like below.\n", - "array([[ 0, 0, 0],\n", - " [ 4, 0, 0],\n", - " [ 7, 8, 0],\n", - " [10, 11, 12]])" - ] - }, - { - "cell_type": "code", - "execution_count": 101, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[ 0, 0, 0],\n", - " [ 4, 0, 0],\n", - " [ 7, 8, 0],\n", - " [10, 11, 12]])" - ] - }, - "execution_count": 101, - "metadata": {}, - "output_type": "execute_result" + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Tzb4RqzxwY8b" + }, + "source": [ + "# Array creation routines" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "o1x4-sHzwY8c" + }, + "source": [ + "## Ones and zeros" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true, + "id": "nMqGZcj2wY8c" + }, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "snOe1aqUwY8d" + }, + "source": [ + "Create a new array of 2*2 integers, without initializing entries." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "T-Knln88wY8d", + "outputId": "458e2675-1e4e-416e-e3f6-1b2d3d453625" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[101640133937702, 0],\n", + " [ 1, 135849737908256]])" + ] + }, + "metadata": {}, + "execution_count": 2 + } + ], + "source": [ + "np.empty([2,2], int)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "jFvxw128wY8d" + }, + "source": [ + "Let X = np.array([1,2,3], [4,5,6], np.int32).\n", + "Create a new array with the same shape and type as X." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "6Wtl27vPwY8d", + "outputId": "372fd33f-99fb-4c58-8964-94fca90b58ce" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[ 0, 1072693248, 0],\n", + " [1072693248, 0, 1072693248]], dtype=int32)" + ] + }, + "metadata": {}, + "execution_count": 3 + } + ], + "source": [ + "X = np.array([[1,2,3], [4,5,6]], np.int32)\n", + "np.empty_like(X)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "jjjE-IdKwY8e" + }, + "source": [ + "Create a 3-D array with ones on the diagonal and zeros elsewhere." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "-rcMZ7bdwY8e", + "outputId": "0515bc02-f38c-465e-8b07-92fd1158d934" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1., 0., 0.],\n", + " [0., 1., 0.],\n", + " [0., 0., 1.]])" + ] + }, + "metadata": {}, + "execution_count": 4 + } + ], + "source": [ + "np.eye(3)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "dyWidWYlwY8e", + "outputId": "366a8f95-c18a-4c26-af90-561764c19df6" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1., 0., 0.],\n", + " [0., 1., 0.],\n", + " [0., 0., 1.]])" + ] + }, + "metadata": {}, + "execution_count": 5 + } + ], + "source": [ + "np.identity(3)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "kctP_1ouwY8e" + }, + "source": [ + "Create a new array of 3*2 float numbers, filled with ones." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "OlfR0HhMwY8e", + "outputId": "bfdb50fb-2cf4-48e2-c86f-29c21d7b182e" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1., 1.],\n", + " [1., 1.],\n", + " [1., 1.]])" + ] + }, + "metadata": {}, + "execution_count": 6 + } + ], + "source": [ + "np.ones([3,2], float)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "gRGVGDq0wY8e" + }, + "source": [ + "Let x = np.arange(4, dtype=np.int64). Create an array of ones with the same shape and type as X." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "V_7LhL5ewY8e", + "outputId": "31e08f50-e196-4c5d-fd3f-7554454dcab4" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([1, 1, 1, 1])" + ] + }, + "metadata": {}, + "execution_count": 7 + } + ], + "source": [ + "x = np.arange(4, dtype=np.int64)\n", + "np.ones_like(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "kvnYNxC9wY8e" + }, + "source": [ + "Create a new array of 3*2 float numbers, filled with zeros." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "eRZFLjeOwY8e", + "outputId": "5d3bb82d-47db-4509-de41-c2f1c7bcb6b6" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[0., 0.],\n", + " [0., 0.],\n", + " [0., 0.]])" + ] + }, + "metadata": {}, + "execution_count": 8 + } + ], + "source": [ + "np.zeros((3,2), float)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "E0IsvdbUwY8e" + }, + "source": [ + "Let x = np.arange(4, dtype=np.int64). Create an array of zeros with the same shape and type as X." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "EE9LG_ZfwY8f", + "outputId": "642a555e-c69e-4925-a019-cf9ed5ae45ec" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([0, 0, 0, 0])" + ] + }, + "metadata": {}, + "execution_count": 9 + } + ], + "source": [ + "x = np.arange(4, dtype=np.int64)\n", + "np.zeros_like(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7D0j64s_wY8f" + }, + "source": [ + "Create a new array of 2*5 uints, filled with 6." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "8P_McXwjwY8f", + "outputId": "8efeb324-89c1-4bb6-a8a2-1b674d895cbc" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[6, 6, 6, 6, 6],\n", + " [6, 6, 6, 6, 6]], dtype=uint64)" + ] + }, + "metadata": {}, + "execution_count": 10 + } + ], + "source": [ + "np.full((2, 5), 6, dtype=np.uint)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "yVATjeqVwY8f", + "outputId": "c8238db0-e66c-48f8-cdd9-29ed476f6384" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[6, 6, 6, 6, 6],\n", + " [6, 6, 6, 6, 6]], dtype=uint64)" + ] + }, + "metadata": {}, + "execution_count": 11 + } + ], + "source": [ + "np.ones([2, 5], dtype=np.uint) * 6" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "dmPnV9vIwY8f" + }, + "source": [ + "Let x = np.arange(4, dtype=np.int64). Create an array of 6's with the same shape and type as X." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "U08RK_xZwY8f", + "outputId": "374bb52e-4c22-44ee-81c6-f093d7482f1c" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([6, 6, 6, 6])" + ] + }, + "metadata": {}, + "execution_count": 12 + } + ], + "source": [ + "x = np.arange(4, dtype=np.int64)\n", + "np.full_like(x, 6)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "9nLfdzOHwY8f", + "outputId": "fa0dbbe5-9557-4ec3-f5ff-7d1353e84dc6" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([6, 6, 6, 6])" + ] + }, + "metadata": {}, + "execution_count": 13 + } + ], + "source": [ + "np.ones_like(x) * 6" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "o2T1C2dLwY8f" + }, + "source": [ + "## From existing data" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "iX9LKZHZwY8f" + }, + "source": [ + "Create an array of [1, 2, 3]." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "fYabJ7pZwY8f", + "outputId": "ad974d66-3788-4133-8ced-09d51b6b17be" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([1, 2, 3])" + ] + }, + "metadata": {}, + "execution_count": 14 + } + ], + "source": [ + "np.array([1, 2, 3])" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "O9nnGn4-wY8f" + }, + "source": [ + "Let x = [1, 2]. Convert it into an array." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "bOpnbHYpwY8f", + "outputId": "601cd5f2-0467-47e9-b9fe-7ea8018f28df" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([1, 2])" + ] + }, + "metadata": {}, + "execution_count": 15 + } + ], + "source": [ + "x = [1,2]\n", + "np.asarray(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "9FogCrWmwY8f" + }, + "source": [ + "Let X = np.array([[1, 2], [3, 4]]). Convert it into a matrix." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "0M9nqqHawY8f", + "outputId": "0bfbfab6-a72b-4e1c-f94a-ec8ec72cbebd" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "matrix([[1, 2],\n", + " [3, 4]])" + ] + }, + "metadata": {}, + "execution_count": 16 + } + ], + "source": [ + "X = np.array([[1, 2], [3, 4]])\n", + "np.asmatrix(X)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FOx7aFWgwY8f" + }, + "source": [ + "Let x = [1, 2]. Conver it into an array of `float`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "4sOZ-w5iwY8f", + "outputId": "9062e274-b2e8-4052-a033-e1fc450ca37a" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([1., 2.])" + ] + }, + "metadata": {}, + "execution_count": 17 + } + ], + "source": [ + "x = [1, 2]\n", + "np.asfarray(x)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "Tj6IOh8RwY8g", + "outputId": "6a5076f7-8411-49b5-c25c-2b753489e2b7" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([1., 2.])" + ] + }, + "metadata": {}, + "execution_count": 18 + } + ], + "source": [ + "np.asarray(x, float)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "_S1aaA0iwY8g" + }, + "source": [ + "Let x = np.array([30]). Convert it into scalar of its single element, i.e. 30." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "3D-jBuodwY8g", + "outputId": "71a3fda3-783f-4582-b331-dae3a6e6e891" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "30" + ] + }, + "metadata": {}, + "execution_count": 19 + } + ], + "source": [ + "x = np.array([30])\n", + "x.item()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "4XUBEauIwY8g", + "outputId": "72b3ad1b-5f6f-4b58-b8f2-238bdc551dd3" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "30" + ] + }, + "metadata": {}, + "execution_count": 20 + } + ], + "source": [ + "x[0]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "XLJ1m2_nwY8g" + }, + "source": [ + "Let x = np.array([1, 2, 3]). Create a array copy of x, which has a different id from x." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "sF_rk01iwY8g", + "outputId": "394267cf-f15d-46bb-c680-56a21f4a4ff9" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "135849319563056 [1 2 3]\n", + "135849319931824 [1 2 3]\n" + ] + } + ], + "source": [ + "x = np.array([1, 2, 3])\n", + "y = np.copy(x)\n", + "print (id(x), x)\n", + "print (id(y), y)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7zn6ntbywY8g" + }, + "source": [ + "## Numerical ranges" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Xp2CZ7YswY8g" + }, + "source": [ + "Create an array of 2, 4, 6, 8, ..., 100." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "IifI2aGEwY8g", + "outputId": "a071276d-a269-4032-a29f-3e778a15d358" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26,\n", + " 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52,\n", + " 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78,\n", + " 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100])" + ] + }, + "metadata": {}, + "execution_count": 22 + } + ], + "source": [ + "np.arange(2, 101, 2)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "XERc8PlEwY8g" + }, + "source": [ + "Create a 1-D array of 50 evenly spaced elements between 3. and 10., inclusive." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "_AXadv6ywY8g", + "outputId": "0f471a2b-c9dd-49b2-da93-db758212767e" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([ 3. , 3.14285714, 3.28571429, 3.42857143, 3.57142857,\n", + " 3.71428571, 3.85714286, 4. , 4.14285714, 4.28571429,\n", + " 4.42857143, 4.57142857, 4.71428571, 4.85714286, 5. ,\n", + " 5.14285714, 5.28571429, 5.42857143, 5.57142857, 5.71428571,\n", + " 5.85714286, 6. , 6.14285714, 6.28571429, 6.42857143,\n", + " 6.57142857, 6.71428571, 6.85714286, 7. , 7.14285714,\n", + " 7.28571429, 7.42857143, 7.57142857, 7.71428571, 7.85714286,\n", + " 8. , 8.14285714, 8.28571429, 8.42857143, 8.57142857,\n", + " 8.71428571, 8.85714286, 9. , 9.14285714, 9.28571429,\n", + " 9.42857143, 9.57142857, 9.71428571, 9.85714286, 10. ])" + ] + }, + "metadata": {}, + "execution_count": 23 + } + ], + "source": [ + "np.linspace(3., 10, 50)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "kyCQttMpwY8h" + }, + "source": [ + "Create a 1-D array of 50 element spaced evenly on a log scale between 3. and 10., exclusive." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "BReqbXxFwY8h", + "outputId": "0169a0e2-a86e-4eb0-a88e-1e747634f43a" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([1.00000000e+03, 1.38038426e+03, 1.90546072e+03, 2.63026799e+03,\n", + " 3.63078055e+03, 5.01187234e+03, 6.91830971e+03, 9.54992586e+03,\n", + " 1.31825674e+04, 1.81970086e+04, 2.51188643e+04, 3.46736850e+04,\n", + " 4.78630092e+04, 6.60693448e+04, 9.12010839e+04, 1.25892541e+05,\n", + " 1.73780083e+05, 2.39883292e+05, 3.31131121e+05, 4.57088190e+05,\n", + " 6.30957344e+05, 8.70963590e+05, 1.20226443e+06, 1.65958691e+06,\n", + " 2.29086765e+06, 3.16227766e+06, 4.36515832e+06, 6.02559586e+06,\n", + " 8.31763771e+06, 1.14815362e+07, 1.58489319e+07, 2.18776162e+07,\n", + " 3.01995172e+07, 4.16869383e+07, 5.75439937e+07, 7.94328235e+07,\n", + " 1.09647820e+08, 1.51356125e+08, 2.08929613e+08, 2.88403150e+08,\n", + " 3.98107171e+08, 5.49540874e+08, 7.58577575e+08, 1.04712855e+09,\n", + " 1.44543977e+09, 1.99526231e+09, 2.75422870e+09, 3.80189396e+09,\n", + " 5.24807460e+09, 7.24435960e+09])" + ] + }, + "metadata": {}, + "execution_count": 24 + } + ], + "source": [ + "np.logspace(3., 10., 50, endpoint=False)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "nurV5Aa2wY8h" + }, + "source": [ + "## Building matrices" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "-sw3tBEMwY8h" + }, + "source": [ + "Let X = np.array([[ 0, 1, 2, 3],\n", + " [ 4, 5, 6, 7],\n", + " [ 8, 9, 10, 11]]).\n", + " Get the diagonal of X, that is, [0, 5, 10]." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "njZN065SwY8h", + "outputId": "2ab2bfc7-16a4-417c-f80a-b0578ca187ce" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([ 0, 5, 10])" + ] + }, + "metadata": {}, + "execution_count": 25 + } + ], + "source": [ + "X = np.array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]])\n", + "np.diag(X)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "ESVl4uVYwY8h", + "outputId": "84a6bbcc-e7d2-44ef-cc88-79049d1ac858" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([ 0, 5, 10])" + ] + }, + "metadata": {}, + "execution_count": 26 + } + ], + "source": [ + "X.diagonal()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "HS3emp0hwY8h" + }, + "source": [ + "Create a 2-D array whose diagonal equals [1, 2, 3, 4] and 0's elsewhere." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "ZqZXmE3qwY8h", + "outputId": "447d557c-af4e-4878-bf20-6f5fa935a676" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1, 0, 0, 0],\n", + " [0, 2, 0, 0],\n", + " [0, 0, 3, 0],\n", + " [0, 0, 0, 4]])" + ] + }, + "metadata": {}, + "execution_count": 27 + } + ], + "source": [ + "np.diagflat([1, 2, 3, 4])" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "RuyBaZcXwY8h" + }, + "source": [ + "Create an array which looks like below.\n", + "array([[ 0., 0., 0., 0., 0.],\n", + " [ 1., 0., 0., 0., 0.],\n", + " [ 1., 1., 0., 0., 0.]])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "dBroXcbSwY8h", + "outputId": "f316ba64-618c-4375-d03b-4fdff8fe9867" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[0., 0., 0., 0., 0.],\n", + " [1., 0., 0., 0., 0.],\n", + " [1., 1., 0., 0., 0.]])" + ] + }, + "metadata": {}, + "execution_count": 28 + } + ], + "source": [ + "np.tri(3, 5, -1)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ZkH0ElOowY8h" + }, + "source": [ + "Create an array which looks like below.\n", + "array([[ 0, 0, 0],\n", + " [ 4, 0, 0],\n", + " [ 7, 8, 0],\n", + " [10, 11, 12]])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "vad1cmZ_wY8h", + "outputId": "324eff1e-45b7-4907-8348-a39dbac2d974" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[ 0, 0, 0],\n", + " [ 4, 0, 0],\n", + " [ 7, 8, 0],\n", + " [10, 11, 12]])" + ] + }, + "metadata": {}, + "execution_count": 29 + } + ], + "source": [ + "np.tril(np.arange(1, 13).reshape(4, 3), -1)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "65UsidJ_wY8h" + }, + "source": [ + "Create an array which looks like below. array([[ 1, 2, 3],\n", + " [ 4, 5, 6],\n", + " [ 0, 8, 9],\n", + " [ 0, 0, 12]])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "hmaDDnE7wY8h", + "outputId": "311e88e5-1302-4324-98be-dd9c1538cac3" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[ 1, 2, 3],\n", + " [ 4, 5, 6],\n", + " [ 0, 8, 9],\n", + " [ 0, 0, 12]])" + ] + }, + "metadata": {}, + "execution_count": 30 + } + ], + "source": [ + "np.triu(np.arange(1, 13).reshape(4, 3), -1)" + ] } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create an array which looks like below. array([[ 1, 2, 3],\n", - " [ 4, 5, 6],\n", - " [ 0, 8, 9],\n", - " [ 0, 0, 12]])" - ] - }, - { - "cell_type": "code", - "execution_count": 102, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[ 1, 2, 3],\n", - " [ 4, 5, 6],\n", - " [ 0, 8, 9],\n", - " [ 0, 0, 12]])" - ] - }, - "execution_count": 102, - "metadata": {}, - "output_type": "execute_result" + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + }, + "colab": { + "provenance": [], + "cell_execution_strategy": "setup", + "include_colab_link": true } - ], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 2", - "language": "python", - "name": "python2" }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file diff --git a/2_Array_manipulation_routines.ipynb b/2_Array_manipulation_routines.ipynb index 85243a3..90d4a7b 100644 --- a/2_Array_manipulation_routines.ipynb +++ b/2_Array_manipulation_routines.ipynb @@ -1,736 +1,1019 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Array manipulation routines" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "import numpy as np" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "'1.11.2'" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "np.__version__" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "collapsed": true - }, - "source": [ - "Q1. Let x be a ndarray [10, 10, 3] with all elements set to one. Reshape x so that the size of the second dimension equals 150." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", - " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", - " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", - " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", - " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", - " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", - " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", - " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", - " 1. 1. 1. 1. 1. 1.]\n", - " [ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", - " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", - " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", - " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", - " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", - " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", - " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", - " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", - " 1. 1. 1. 1. 1. 1.]]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q2. Let x be array [[1, 2, 3], [4, 5, 6]]. Convert it to [1 4 2 5 3 6]." - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1 4 2 5 3 6]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q3. Let x be array [[1, 2, 3], [4, 5, 6]]. Get the 5th element." - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "5\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q4. Let x be an arbitrary 3-D array of shape (3, 4, 5). Permute the dimensions of x such that the new shape will be (4,3,5).\n" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(4L, 3L, 5L)\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q5. Let x be an arbitrary 2-D array of shape (3, 4). Permute the dimensions of x such that the new shape will be (4,3)." - ] - }, - { - "cell_type": "code", - "execution_count": 38, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(4L, 3L)\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q5. Let x be an arbitrary 2-D array of shape (3, 4). Insert a nex axis such that the new shape will be (3, 1, 4)." - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(3L, 1L, 4L)\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q6. Let x be an arbitrary 3-D array of shape (3, 4, 1). Remove a single-dimensional entries such that the new shape will be (3, 4)." - ] - }, - { - "cell_type": "code", - "execution_count": 43, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(3L, 4L)\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q7. Lex x be an array
\n", - "[[ 1 2 3]
\n", - "[ 4 5 6].

\n", - "and y be an array
\n", - "[[ 7 8 9]
\n", - "[10 11 12]].
\n", - "Concatenate x and y so that a new array looks like
[[1, 2, 3, 7, 8, 9],
[4, 5, 6, 10, 11, 12]].\n" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[ 1 2 3 7 8 9]\n", - " [ 4 5 6 10 11 12]]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q8. Lex x be an array
\n", - "[[ 1 2 3]
\n", - "[ 4 5 6].

\n", - "and y be an array
\n", - "[[ 7 8 9]
\n", - "[10 11 12]].
\n", - "Concatenate x and y so that a new array looks like
[[ 1 2 3]
\n", - " [ 4 5 6]
\n", - " [ 7 8 9]
\n", - " [10 11 12]]\n" - ] - }, - { - "cell_type": "code", - "execution_count": 38, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[ 1 2 3]\n", - " [ 4 5 6]\n", - " [ 7 8 9]\n", - " [10 11 12]]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q8. Let x be an array [1 2 3] and y be [4 5 6]. Convert it to [[1, 4], [2, 5], [3, 6]]." - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[1 4]\n", - " [2 5]\n", - " [3 6]]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q9. Let x be an array [[1],[2],[3]] and y be [[4], [5], [6]]. Convert x to [[[1, 4]], [[2, 5]], [[3, 6]]]." - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[[1 4]]\n", - "\n", - " [[2 5]]\n", - "\n", - " [[3 6]]]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q10. Let x be an array [1, 2, 3, ..., 9]. Split x into 3 arrays, each of which has 4, 2, and 3 elements in the original order." - ] - }, - { - "cell_type": "code", - "execution_count": 62, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[array([1, 2, 3, 4]), array([5, 6]), array([7, 8, 9])]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q11. Let x be an array
\n", - "[[[ 0., 1., 2., 3.],
\n", - " [ 4., 5., 6., 7.]],
\n", - " \n", - " [[ 8., 9., 10., 11.],
\n", - " [ 12., 13., 14., 15.]]].
\n", - "Split it into two such that the first array looks like
\n", - "[[[ 0., 1., 2.],
\n", - " [ 4., 5., 6.]],
\n", - " \n", - " [[ 8., 9., 10.],
\n", - " [ 12., 13., 14.]]].
\n", - " \n", - "and the second one look like:
\n", - " \n", - "[[[ 3.],
\n", - " [ 7.]],
\n", - " \n", - " [[ 11.],
\n", - " [ 15.]]].
" - ] - }, - { - "cell_type": "code", - "execution_count": 72, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[array([[[ 0, 1, 2],\n", - " [ 4, 5, 6]],\n", - "\n", - " [[ 8, 9, 10],\n", - " [12, 13, 14]]]), array([[[ 3],\n", - " [ 7]],\n", - "\n", - " [[11],\n", - " [15]]])]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q12. Let x be an array
\n", - "[[ 0., 1., 2., 3.],
\n", - " [ 4., 5., 6., 7.],
\n", - " [ 8., 9., 10., 11.],
\n", - " [ 12., 13., 14., 15.]].
\n", - "Split it into two arrays along the second axis." - ] - }, - { - "cell_type": "code", - "execution_count": 74, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[array([[ 0, 1],\n", - " [ 4, 5],\n", - " [ 8, 9],\n", - " [12, 13]]), array([[ 2, 3],\n", - " [ 6, 7],\n", - " [10, 11],\n", - " [14, 15]])]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q13. Let x be an array
\n", - "[[ 0., 1., 2., 3.],
\n", - " [ 4., 5., 6., 7.],
\n", - " [ 8., 9., 10., 11.],
\n", - " [ 12., 13., 14., 15.]].
\n", - "Split it into two arrays along the first axis." - ] - }, - { - "cell_type": "code", - "execution_count": 75, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[array([[0, 1, 2, 3],\n", - " [4, 5, 6, 7]]), array([[ 8, 9, 10, 11],\n", - " [12, 13, 14, 15]])]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q14. Let x be an array [0, 1, 2]. Convert it to
\n", - "[[0, 1, 2, 0, 1, 2],
\n", - " [0, 1, 2, 0, 1, 2]]." - ] - }, - { - "cell_type": "code", - "execution_count": 93, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[0 1 2 0 1 2]\n", - " [0 1 2 0 1 2]]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q15. Let x be an array [0, 1, 2]. Convert it to
\n", - "[0, 0, 1, 1, 2, 2]." - ] - }, - { - "cell_type": "code", - "execution_count": 83, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[0 0 1 1 2 2]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q16. Let x be an array [0, 0, 0, 1, 2, 3, 0, 2, 1, 0].
\n", - "remove the leading the trailing zeros." - ] - }, - { - "cell_type": "code", - "execution_count": 105, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1 2 3 0 2 1]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q17. Let x be an array [2, 2, 1, 5, 4, 5, 1, 2, 3]. Get two arrays of unique elements and their counts.\n" - ] - }, - { - "cell_type": "code", - "execution_count": 107, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1 2 3 4 5] [2 3 1 1 2]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q18. Lex x be an array
\n", - "[[ 1 2]
\n", - " [ 3 4].
\n", - "Flip x along the second axis." - ] - }, - { - "cell_type": "code", - "execution_count": 120, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[2 1]\n", - " [4 3]]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q19. Lex x be an array
\n", - "[[ 1 2]
\n", - " [ 3 4].
\n", - "Flip x along the first axis." - ] - }, - { - "cell_type": "code", - "execution_count": 121, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[3 4]\n", - " [1 2]]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q20. Lex x be an array
\n", - "[[ 1 2]
\n", - " [ 3 4].
\n", - "Rotate x 90 degrees counter-clockwise." - ] - }, - { - "cell_type": "code", - "execution_count": 122, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[2 4]\n", - " [1 3]]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Q21 Lex x be an array
\n", - "[[ 1 2 3 4]
\n", - " [ 5 6 7 8].
\n", - "Shift elements one step to right along the second axis." - ] - }, - { - "cell_type": "code", - "execution_count": 126, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[4 1 2 3]\n", - " [8 5 6 7]]\n" - ] - } - ], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 2", - "language": "python", - "name": "python2" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.10" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FeCSvzn7yLdm" + }, + "source": [ + "# Array manipulation routines" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true, + "id": "-X96ykV3yLdn" + }, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "53iPhefjyLdo", + "outputId": "7911cab9-1a27-4068-a0e3-ef74f22a5ee2", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'1.25.2'" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 2 + } + ], + "source": [ + "np.__version__" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true, + "id": "Zy7UoA_CyLdp" + }, + "source": [ + "Q1. Let x be a ndarray [10, 10, 3] with all elements set to one. Reshape x so that the size of the second dimension equals 150." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "id": "2fpIMT5SyLdp", + "outputId": "000dedbd-4244-4c36-d01a-0444e8bd83a1", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", + " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", + " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", + " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", + " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", + " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", + " 1. 1. 1. 1. 1. 1.]\n", + " [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", + " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", + " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", + " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", + " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", + " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n", + " 1. 1. 1. 1. 1. 1.]]\n" + ] + } + ], + "source": [ + "x = np.ones([10, 10, 3])\n", + "out = np.reshape(x, [-1, 150])\n", + "print (out)\n", + "assert np.allclose(out, np.ones([10, 10, 3]).reshape([-1, 150]))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "b4KrOPRvyLdp" + }, + "source": [ + "Q2. Let x be array [[1, 2, 3], [4, 5, 6]]. Convert it to [1 4 2 5 3 6]." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "id": "mp9cPSiEyLdq", + "outputId": "e739f8cc-be80-4451-cf0b-4aff15b1945d", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[1 4 2 5 3 6]\n" + ] + } + ], + "source": [ + "x = np.array([[1, 2, 3], [4, 5, 6]])\n", + "out1 = np.ravel(x, order='F')\n", + "out2 = x.flatten(order=\"F\")\n", + "assert np.allclose(out1, out2)\n", + "print (out1)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "cFNwUvCByLdq" + }, + "source": [ + "Q3. Let x be array [[1, 2, 3], [4, 5, 6]]. Get the 5th element." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "id": "THZIM1khyLdq", + "outputId": "c4b70f96-67c1-4056-9160-61d30531d482", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "5\n" + ] + } + ], + "source": [ + "x = np.array([[1, 2, 3], [4, 5, 6]])\n", + "out1 = x.flat[4]\n", + "out2 = np.ravel(x)[4]\n", + "assert np.allclose(out1, out2)\n", + "print (out1)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "NuebMeLQyLdq" + }, + "source": [ + "Q4. Let x be an arbitrary 3-D array of shape (3, 4, 5). Permute the dimensions of x such that the new shape will be (4,3,5).\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "id": "goI2ZWxNyLdr", + "outputId": "17c0acf9-1b59-4f95-c053-a4396f7bc52a", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(4, 3, 5)\n" + ] + } + ], + "source": [ + "x = np.zeros((3, 4, 5))\n", + "out1 = np.swapaxes(x, 1, 0)\n", + "out2 = x.transpose([1, 0, 2])\n", + "assert out1.shape == out2.shape\n", + "print (out1.shape)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Og_a0d6myLdr" + }, + "source": [ + "Q5. Let x be an arbitrary 2-D array of shape (3, 4). Permute the dimensions of x such that the new shape will be (4,3)." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "id": "HdGDLSYiyLdr", + "outputId": "7d3e0c45-26bd-473c-8372-293dd68eedb7", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(4, 3)\n" + ] + } + ], + "source": [ + "x = np.zeros((3, 4))\n", + "out1 = np.swapaxes(x, 1, 0)\n", + "out2 = x.transpose()\n", + "out3 = x.T\n", + "assert out1.shape == out2.shape == out3.shape\n", + "print (out1.shape)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Dt0P-9u3yLdr" + }, + "source": [ + "Q5. Let x be an arbitrary 2-D array of shape (3, 4). Insert a nex axis such that the new shape will be (3, 1, 4)." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "ELkIP5pCyLds", + "outputId": "722dcfeb-5540-4d42-8d9b-2842e0d882f5", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(3, 1, 4)\n" + ] + } + ], + "source": [ + "x = np.zeros((3, 4))\n", + "print (np.expand_dims(x, axis=1).shape)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "NjTSGEBRyLds" + }, + "source": [ + "Q6. Let x be an arbitrary 3-D array of shape (3, 4, 1). Remove a single-dimensional entries such that the new shape will be (3, 4)." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "id": "An2wbjjUyLds", + "outputId": "95806de5-f643-4ebd-bb89-a5b1bba5ba94", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(3, 4)\n" + ] + } + ], + "source": [ + "x = np.zeros((3, 4, 1))\n", + "print (np.squeeze(x).shape)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4oXZdOOcyLds" + }, + "source": [ + "Q7. Lex x be an array
\n", + "[[ 1 2 3]
\n", + "[ 4 5 6].

\n", + "and y be an array
\n", + "[[ 7 8 9]
\n", + "[10 11 12]].
\n", + "Concatenate x and y so that a new array looks like
[[1, 2, 3, 7, 8, 9],
[4, 5, 6, 10, 11, 12]].\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "id": "CZqmneq6yLds", + "outputId": "614cc9eb-8026-4601-d57e-6ecd51b6f20c", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[ 1 2 3 7 8 9]\n", + " [ 4 5 6 10 11 12]]\n" + ] + } + ], + "source": [ + "x = np.array([[1, 2, 3], [4, 5, 6]])\n", + "y = np.array([[7, 8, 9], [10, 11, 12]])\n", + "out1 = np.concatenate((x, y), 1)\n", + "out2 = np.hstack((x, y))\n", + "assert np.allclose(out1, out2)\n", + "print (out2)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "gSKH6bQkyLdt" + }, + "source": [ + "Q8. Lex x be an array
\n", + "[[ 1 2 3]
\n", + "[ 4 5 6].

\n", + "and y be an array
\n", + "[[ 7 8 9]
\n", + "[10 11 12]].
\n", + "Concatenate x and y so that a new array looks like
[[ 1 2 3]
\n", + " [ 4 5 6]
\n", + " [ 7 8 9]
\n", + " [10 11 12]]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "id": "yDgRO4IPyLdt", + "outputId": "b86d2472-63a4-486c-d5cd-0e605ead932f", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[ 1 2 3]\n", + " [ 4 5 6]\n", + " [ 7 8 9]\n", + " [10 11 12]]\n" + ] + } + ], + "source": [ + "x = np.array([[1, 2, 3], [4, 5, 6]])\n", + "y = np.array([[7, 8, 9], [10, 11, 12]])\n", + "out1 = np.concatenate((x, y), 0)\n", + "out2 = np.vstack((x, y))\n", + "assert np.allclose(out1, out2)\n", + "print (out2)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "9AaOsEWzyLdt" + }, + "source": [ + "Q8. Let x be an array [1 2 3] and y be [4 5 6]. Convert it to [[1, 4], [2, 5], [3, 6]]." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "id": "2nf6dYi2yLdt", + "outputId": "80897d83-77ff-4bc5-b3c8-4e1e71e02599", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[1 4]\n", + " [2 5]\n", + " [3 6]]\n" + ] + } + ], + "source": [ + "x = np.array((1,2,3))\n", + "y = np.array((4,5,6))\n", + "out1 = np.column_stack((x, y))\n", + "out2 = np.squeeze(np.dstack((x, y)))\n", + "out3 = np.vstack((x, y)).T\n", + "assert np.allclose(out1, out2)\n", + "assert np.allclose(out2, out3)\n", + "print (out1)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "XmQ-SP01yLdt" + }, + "source": [ + "Q9. Let x be an array [[1],[2],[3]] and y be [[4], [5], [6]]. Convert x to [[[1, 4]], [[2, 5]], [[3, 6]]]." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "id": "hCm22Ut_yLdu", + "outputId": "a9b7e842-f0ab-4db4-a100-e3a797a82dde", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[[1 4]]\n", + "\n", + " [[2 5]]\n", + "\n", + " [[3 6]]]\n" + ] + } + ], + "source": [ + "x = np.array([[1],[2],[3]])\n", + "y = np.array([[4],[5],[6]])\n", + "out = np.dstack((x, y))\n", + "print (out)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Q2jNdblGyLdu" + }, + "source": [ + "Q10. Let x be an array [1, 2, 3, ..., 9]. Split x into 3 arrays, each of which has 4, 2, and 3 elements in the original order." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "id": "ityFiwBZyLdu", + "outputId": "7e389434-ec36-44d9-ef50-cb5f83cbd0f1", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[array([1, 2, 3, 4]), array([5, 6]), array([7, 8, 9])]\n" + ] + } + ], + "source": [ + "x = np.arange(1, 10)\n", + "print (np.split(x, [4, 6]))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "pAUC8PFAyLdu" + }, + "source": [ + "Q11. Let x be an array
\n", + "[[[ 0., 1., 2., 3.],
\n", + " [ 4., 5., 6., 7.]],
\n", + "\n", + " [[ 8., 9., 10., 11.],
\n", + " [ 12., 13., 14., 15.]]].
\n", + "Split it into two such that the first array looks like
\n", + "[[[ 0., 1., 2.],
\n", + " [ 4., 5., 6.]],
\n", + "\n", + " [[ 8., 9., 10.],
\n", + " [ 12., 13., 14.]]].
\n", + " \n", + "and the second one look like:
\n", + " \n", + "[[[ 3.],
\n", + " [ 7.]],
\n", + "\n", + " [[ 11.],
\n", + " [ 15.]]].
" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "id": "bjw_05ITyLdu", + "outputId": "69574982-da83-430b-844f-85f957a23af8", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[array([[[ 0, 1, 2],\n", + " [ 4, 5, 6]],\n", + "\n", + " [[ 8, 9, 10],\n", + " [12, 13, 14]]]), array([[[ 3],\n", + " [ 7]],\n", + "\n", + " [[11],\n", + " [15]]])]\n" + ] + } + ], + "source": [ + "x = np.arange(16).reshape(2, 2, 4)\n", + "out1 = np.split(x, [3],axis=2)\n", + "out2 = np.dsplit(x, [3])\n", + "assert np.allclose(out1[0], out2[0])\n", + "assert np.allclose(out1[1], out2[1])\n", + "print (out1)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Ai0YM6umyLdu" + }, + "source": [ + "Q12. Let x be an array
\n", + "[[ 0., 1., 2., 3.],
\n", + " [ 4., 5., 6., 7.],
\n", + " [ 8., 9., 10., 11.],
\n", + " [ 12., 13., 14., 15.]].
\n", + "Split it into two arrays along the second axis." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "id": "1WVXzXUIyLdu", + "outputId": "28a67b84-62a6-425d-edf8-0564dcc9c32a", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[array([[ 0, 1],\n", + " [ 4, 5],\n", + " [ 8, 9],\n", + " [12, 13]]), array([[ 2, 3],\n", + " [ 6, 7],\n", + " [10, 11],\n", + " [14, 15]])]\n" + ] + } + ], + "source": [ + "x = np.arange(16).reshape((4, 4))\n", + "out1 = np.hsplit(x, 2)\n", + "out2 = np.split(x, 2, 1)\n", + "assert np.allclose(out1[0], out2[0])\n", + "assert np.allclose(out1[1], out2[1])\n", + "print (out1)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "nx4dR4F8yLdv" + }, + "source": [ + "Q13. Let x be an array
\n", + "[[ 0., 1., 2., 3.],
\n", + " [ 4., 5., 6., 7.],
\n", + " [ 8., 9., 10., 11.],
\n", + " [ 12., 13., 14., 15.]].
\n", + "Split it into two arrays along the first axis." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "id": "Q5NEvUALyLdv", + "outputId": "5c7e686d-2e5b-4283-dfee-930c91a07352", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[array([[0, 1, 2, 3],\n", + " [4, 5, 6, 7]]), array([[ 8, 9, 10, 11],\n", + " [12, 13, 14, 15]])]\n" + ] + } + ], + "source": [ + "x = np.arange(16).reshape((4, 4))\n", + "out1 = np.vsplit(x, 2)\n", + "out2 = np.split(x, 2, 0)\n", + "assert np.allclose(out1[0], out2[0])\n", + "assert np.allclose(out1[1], out2[1])\n", + "print (out1)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Mc2qzQSdyLdv" + }, + "source": [ + "Q14. Let x be an array [0, 1, 2]. Convert it to
\n", + "[[0, 1, 2, 0, 1, 2],
\n", + " [0, 1, 2, 0, 1, 2]]." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "id": "4RH_svYWyLdv", + "outputId": "aaf95c15-39aa-43a0-de10-03024a8f47ca", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[0 1 2 0 1 2]\n", + " [0 1 2 0 1 2]]\n" + ] + } + ], + "source": [ + "x = np.array([0, 1, 2])\n", + "out1 = np.tile(x, [2, 2])\n", + "out2 = np.resize(x, [2, 6])\n", + "assert np.allclose(out1, out2)\n", + "print (out1)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "LpEpNO2OyLdv" + }, + "source": [ + "Q15. Let x be an array [0, 1, 2]. Convert it to
\n", + "[0, 0, 1, 1, 2, 2]." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "id": "fepjs25zyLdw", + "outputId": "2b884a20-cd48-4031-8623-c943966df656", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[0 0 1 1 2 2]\n" + ] + } + ], + "source": [ + "x = np.array([0, 1, 2])\n", + "print (np.repeat(x, 2))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "X__2KBi7yLdw" + }, + "source": [ + "Q16. Let x be an array [0, 0, 0, 1, 2, 3, 0, 2, 1, 0].
\n", + "remove the leading the trailing zeros." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "id": "nZkAIy0yyLdw", + "outputId": "7c0428bf-e35e-4395-c089-4071cfa2344f", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[1 2 3 0 2 1]\n" + ] + } + ], + "source": [ + "x = np.array((0, 0, 0, 1, 2, 3, 0, 2, 1, 0))\n", + "out = np.trim_zeros(x)\n", + "print (out)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ZCla94rIyLd4" + }, + "source": [ + "Q17. Let x be an array [2, 2, 1, 5, 4, 5, 1, 2, 3]. Get two arrays of unique elements and their counts.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "id": "0mjoIo9NyLd4", + "outputId": "eb275bd5-4fee-4762-90d9-37c07d72fa4d", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[1 2 3 4 5] [2 3 1 1 2]\n" + ] + } + ], + "source": [ + "x = np.array([2, 2, 1, 5, 4, 5, 1, 2, 3])\n", + "u, indices = np.unique(x, return_counts=True)\n", + "print (u, indices)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "qEieNh4lyLd4" + }, + "source": [ + "Q18. Lex x be an array
\n", + "[[ 1 2]
\n", + " [ 3 4].
\n", + "Flip x along the second axis." + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "id": "CASD0V35yLd5", + "outputId": "74530152-a5c1-45ae-8ddd-a27151bcf4c2", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[2 1]\n", + " [4 3]]\n" + ] + } + ], + "source": [ + "x = np.array([[1,2], [3,4]])\n", + "out1 = np.fliplr(x)\n", + "out2 = x[:, ::-1]\n", + "assert np.allclose(out1, out2)\n", + "print (out1)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4Eq4gn12yLd5" + }, + "source": [ + "Q19. Lex x be an array
\n", + "[[ 1 2]
\n", + " [ 3 4].
\n", + "Flip x along the first axis." + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "id": "Ml5CXwQMyLd5", + "outputId": "0fb6bc9f-eae7-4e8e-e46e-434565375c9f", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[3 4]\n", + " [1 2]]\n" + ] + } + ], + "source": [ + "x = np.array([[1,2], [3,4]])\n", + "out1 = np.flipud(x)\n", + "out2 = x[::-1, :]\n", + "assert np.allclose(out1, out2)\n", + "print (out1)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "QugKOBynyLd5" + }, + "source": [ + "Q20. Lex x be an array
\n", + "[[ 1 2]
\n", + " [ 3 4].
\n", + "Rotate x 90 degrees counter-clockwise." + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "id": "cu6I4iIcyLd5", + "outputId": "5c23cf70-6b21-4aa0-f2d8-b56fb4430fb5", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[2 4]\n", + " [1 3]]\n" + ] + } + ], + "source": [ + "x = np.array([[1,2], [3,4]])\n", + "out = np.rot90(x)\n", + "print (out)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "s88mZcECyLd5" + }, + "source": [ + "Q21 Lex x be an array
\n", + "[[ 1 2 3 4]
\n", + " [ 5 6 7 8].
\n", + "Shift elements one step to right along the second axis." + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "id": "6ZK-MNUmyLd5", + "outputId": "bfa1f965-6815-4c65-c1a3-385fc9f82d2e", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[4 1 2 3]\n", + " [8 5 6 7]]\n" + ] + } + ], + "source": [ + "x = np.arange(1, 9).reshape([2, 4])\n", + "print (np.roll(x, 1, axis=1))" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "collapsed": true, + "id": "IjegTkAFyLd6" + }, + "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" + }, + "colab": { + "provenance": [], + "include_colab_link": true + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file