diff --git a/.ipynb_checkpoints/3. NumPy exercises-checkpoint_resol.ipynb b/.ipynb_checkpoints/3. NumPy exercises-checkpoint_resol.ipynb new file mode 100644 index 0000000..504cc6d --- /dev/null +++ b/.ipynb_checkpoints/3. NumPy exercises-checkpoint_resol.ipynb @@ -0,0 +1,2156 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "2LIHc46nrc63" + }, + "source": [ + "![rmotr](https://user-images.githubusercontent.com/7065401/52071918-bda15380-2562-11e9-828c-7f95297e4a82.png)\n", + "
\n", + "\n", + "# NumPy exercises\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "_bqfG08Vrc66" + }, + "outputs": [], + "source": [ + "# Import the numpy package under the name np\n", + "import numpy as np\n", + "\n", + "# Print the numpy version and the configuration\n", + "print(np.__version__)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "olQsGV29rc68" + }, + "source": [ + "![purple-divider](https://user-images.githubusercontent.com/7065401/52071927-c1cd7100-2562-11e9-908a-dde91ba14e59.png)\n", + "\n", + "## Array creation" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "MD2YssNZrc68" + }, + "source": [ + "### Create a numpy array of size 10, filled with zeros." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "id": "bLrIpf_Qrc69", + "outputId": "1f2958a8-dc55-4329-c17e-ff8280adae46", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])" + ] + }, + "metadata": {}, + "execution_count": 3 + } + ], + "source": [ + "# your code goes here\n", + "import numpy as np\n", + "\n", + "np.array([0]*10)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "cell_type": "solution", + "id": "zH_kJyL2rc69", + "outputId": "1c286e34-9403-457f-f6ef-2d84c2b10a83", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])" + ] + }, + "metadata": {}, + "execution_count": 5 + } + ], + "source": [ + "np.array([0] * 10)\n", + "#np.zeros(10)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ZXhdQVkcrc6-" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Create a numpy array with values ranging from 10 to 49" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "id": "jMI49cYArc6-", + "outputId": "9ad0f26d-6dfb-49a4-9450-7e1ca7579766", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,\n", + " 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,\n", + " 44, 45, 46, 47, 48, 49])" + ] + }, + "metadata": {}, + "execution_count": 7 + } + ], + "source": [ + "# your code goes here\n", + "np.arange(10,50)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "9ZQ59HbUrc6_" + }, + "outputs": [], + "source": [ + "np.arange(10,50)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "A59gy-eBrc6_" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Create a numpy matrix of 2*2 integers, filled with ones." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "id": "lWfi8jzmrc7A", + "outputId": "40d1fc78-a4f9-46a2-e087-9a9217051746", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1, 1],\n", + " [1, 1]])" + ] + }, + "metadata": {}, + "execution_count": 14 + } + ], + "source": [ + "# your code goes here\n", + "np.ones([2,2], dtype=int)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "cell_type": "solution", + "id": "plRzG7jDrc7A", + "outputId": "b81c592d-a0c1-41c6-aeed-d2b85f8fe540", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": [ + "/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:1: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.\n", + "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", + " \"\"\"Entry point for launching an IPython kernel.\n" + ] + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1, 1],\n", + " [1, 1]])" + ] + }, + "metadata": {}, + "execution_count": 12 + } + ], + "source": [ + "np.ones([2,2], dtype=np.int)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "fZ1waGNGrc7B" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Create a numpy matrix of 3*2 float numbers, filled with ones." + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "id": "M4-NatP7rc7B", + "outputId": "0e8f65cc-eea0-498f-c51f-4c727f586056", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1., 1.],\n", + " [1., 1.],\n", + " [1., 1.]])" + ] + }, + "metadata": {}, + "execution_count": 15 + } + ], + "source": [ + "# your code goes here\n", + "np.ones([3,2],dtype=float)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "cell_type": "solution", + "id": "X4W5jVEMrc7B", + "outputId": "ea4ad2c7-c102-45f6-dfbb-b3cb83f35c6e", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": [ + "/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:1: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n", + "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n", + " \"\"\"Entry point for launching an IPython kernel.\n" + ] + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1., 1.],\n", + " [1., 1.],\n", + " [1., 1.]])" + ] + }, + "metadata": {}, + "execution_count": 16 + } + ], + "source": [ + "np.ones([3,2], dtype=np.float)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5HKQw8cqrc7B" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy array, create a new numpy array with the same shape and type as X, filled with ones." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "m5poCDu4rc7C" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "NflB968Arc7D" + }, + "outputs": [], + "source": [ + "X = np.arange(4, dtype=np.int)\n", + "\n", + "np.ones_like(X)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Dgx2V3Ydrc7D" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy matrix, create a new numpy matrix with the same shape and type as X, filled with zeros." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "CAoPuAv_rc7D" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "LwIBYck9rc7D" + }, + "outputs": [], + "source": [ + "X = np.array([[1,2,3], [4,5,6]], dtype=np.int)\n", + "\n", + "np.zeros_like(X)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "RHwP-_d1rc7E" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Create a numpy matrix of 4*4 integers, filled with fives." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Fh6lN5R4rc7E" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "FtlBtvNqrc7E" + }, + "outputs": [], + "source": [ + "np.ones([4,4], dtype=np.int) * 5" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SjnCFicFrc7E" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy matrix, create a new numpy matrix with the same shape and type as X, filled with sevens." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "K6qF-zw-rc7F" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "D82OCqzCrc7F" + }, + "outputs": [], + "source": [ + "X = np.array([[2,3], [6,2]], dtype=np.int)\n", + "\n", + "np.ones_like(X) * 7" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "rWzjwkZwrc7F" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Create a 3*3 identity numpy matrix with ones on the diagonal and zeros elsewhere." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "TkYVc3k7rc7F" + }, + "outputs": [], + "source": [ + "# your code goes here" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "_n0sYKlFrc7F" + }, + "outputs": [], + "source": [ + "#np.eye(3)\n", + "np.identity(3)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "shPFREParc7F" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Create a numpy array, filled with 3 random integer values between 1 and 10." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "rzmMvcRPrc7G" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "qi325ovlrc7G" + }, + "outputs": [], + "source": [ + "np.random.randint(10, size=3)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ZkRFMxQgrc7G" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Create a 3\\*3\\*3 numpy matrix, filled with random float values." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "YpJH5lzfrc7G" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "xMv9p5Ojrc7G" + }, + "outputs": [], + "source": [ + "#np.random.random((3,3,3)) \n", + "np.random.randn(3,3,3) # 0 to 1 floats" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "IP5NrKx7rc7G" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X python list convert it to an Y numpy array" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "_sJI9J5Erc7H" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "NNIgAWGcrc7H" + }, + "outputs": [], + "source": [ + "X = [1, 2, 3]\n", + "print(X, type(X))\n", + "\n", + "Y = np.array(X)\n", + "print(Y, type(Y)) # different type" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "u0z-FxEyrc7H" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy array, make a copy and store it on Y." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "vZhFO2CVrc7H" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "ldPfinvfrc7H" + }, + "outputs": [], + "source": [ + "X = np.array([5,2,3], dtype=np.int)\n", + "print(X, id(X))\n", + "\n", + "Y = np.copy(X)\n", + "print(Y, id(Y)) # different id" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ClCRVRB9rc7H" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Create a numpy array with numbers from 1 to 10" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "mBJBdsZnrc7I" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "LAeD0ER0rc7I" + }, + "outputs": [], + "source": [ + "np.arange(1, 11)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "yE2T7Pefrc7I" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Create a numpy array with the odd numbers between 1 to 10" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Qfoc_0xIrc7K" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "lBdWGvd-rc7K" + }, + "outputs": [], + "source": [ + "np.arange(1, 11, 2)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "p7rBXQSVrc7L" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Create a numpy array with numbers from 1 to 10, in descending order." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "g8ZiU2cnrc7L" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "JinenxzFrc7L" + }, + "outputs": [], + "source": [ + "np.arange(1, 11)[::-1]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "JH7O0oAKrc7M" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Create a 3*3 numpy matrix, filled with values ranging from 0 to 8" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "7j6D5C4Frc7M" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "ExY8mXygrc7N" + }, + "outputs": [], + "source": [ + "np.arange(9).reshape(3,3)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "S_SjvgnYrc7N" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Show the memory size of the given Z numpy matrix" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "PMfCsNmUrc7N" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "scrolled": true, + "id": "90NtEZuCrc7O" + }, + "outputs": [], + "source": [ + "Z = np.zeros((10,10))\n", + "\n", + "print(\"%d bytes\" % (Z.size * Z.itemsize))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "KpRUjFFurc7O" + }, + "source": [ + "![purple-divider](https://user-images.githubusercontent.com/7065401/52071927-c1cd7100-2562-11e9-908a-dde91ba14e59.png)\n", + "\n", + "## Array indexation\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DAxewflnrc7P" + }, + "source": [ + "### Given the X numpy array, show it's first element" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "qpq585iarc7P" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "Y6Jae_jsrc7P" + }, + "outputs": [], + "source": [ + "X = np.array(['A','B','C','D','E'])\n", + "\n", + "X[0]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "nt8dN0aQrc7P" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy array, show it's last element" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "TGN2TCEUrc7P" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "zeiBrcbKrc7Q" + }, + "outputs": [], + "source": [ + "X = np.array(['A','B','C','D','E'])\n", + "\n", + "#X[len(X)-1]\n", + "X[-1]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "AIiTeTedrc7Q" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy array, show it's first three elements" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "bu5lHyblrc7Q" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "NNfOSEDOrc7Q" + }, + "outputs": [], + "source": [ + "X = np.array(['A','B','C','D','E'])\n", + "\n", + "X[0:3] # remember! elements start at zero index" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "dUvutE_zrc7R" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy array, show all middle elements" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "vk66eqqwrc7R" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "f5SqNz3Crc7R" + }, + "outputs": [], + "source": [ + "X = np.array(['A','B','C','D','E'])\n", + "\n", + "X[1:-1]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "hZSmyWt-rc7R" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy array, show the elements in reverse position" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "i1wB3aPArc7S" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "t7kcjTJnrc7S" + }, + "outputs": [], + "source": [ + "X = np.array(['A','B','C','D','E'])\n", + "\n", + "X[::-1]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "xPF_kLcLrc7S" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy array, show the elements in an odd position" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "-W2pGsz8rc7T" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "ml9Sl5exrc7T" + }, + "outputs": [], + "source": [ + "X = np.array(['A','B','C','D','E'])\n", + "\n", + "#X[[0, 2, -1]]\n", + "X[::2]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "yGl0dO0vrc7U" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy matrix, show the first row elements" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "VkNuvxh1rc7U" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "uE876trPrc7V" + }, + "outputs": [], + "source": [ + "X = np.array([\n", + " [1, 2, 3, 4],\n", + " [5, 6, 7, 8],\n", + " [9, 10, 11, 12],\n", + " [13, 14, 15, 16]\n", + "])\n", + "\n", + "X[0]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ezE8sletrc7V" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy matrix, show the last row elements" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "6bvVUPDerc7V" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "7tEGFELJrc7W" + }, + "outputs": [], + "source": [ + "X = np.array([\n", + " [1, 2, 3, 4],\n", + " [5, 6, 7, 8],\n", + " [9, 10, 11, 12],\n", + " [13, 14, 15, 16]\n", + "])\n", + "\n", + "X[-1]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "rE5xs6B6rc7W" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy matrix, show the first element on first row" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "kVxUWheIrc7X" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "VHR1sM3frc7X" + }, + "outputs": [], + "source": [ + "X = np.array([\n", + " [1, 2, 3, 4],\n", + " [5, 6, 7, 8],\n", + " [9, 10, 11, 12],\n", + " [13, 14, 15, 16]\n", + "])\n", + "\n", + "#X[0][0]\n", + "X[0, 0]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "vUwMXBj5rc7Z" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy matrix, show the last element on last row" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Ay_ZwQ8prc7Z" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "tS9ld9sDrc7a" + }, + "outputs": [], + "source": [ + "X = np.array([\n", + " [1, 2, 3, 4],\n", + " [5, 6, 7, 8],\n", + " [9, 10, 11, 12],\n", + " [13, 14, 15, 16]\n", + "])\n", + "\n", + "#X[-1][-1]\n", + "X[-1, -1]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "gWLJiiIDrc7a" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy matrix, show the middle row elements" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "ZP0Jhgcmrc7a" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "lb2jrkMRrc7a" + }, + "outputs": [], + "source": [ + "X = np.array([\n", + " [1, 2, 3, 4],\n", + " [5, 6, 7, 8],\n", + " [9, 10, 11, 12],\n", + " [13, 14, 15, 16]\n", + "])\n", + "\n", + "#X[1:-1][1:-1] wrong!\n", + "X[1:-1, 1:-1]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Cbn7kCwDrc7a" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy matrix, show the first two elements on the first two rows" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "FTzSfYxQrc7b" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "-sWSCdc-rc7b" + }, + "outputs": [], + "source": [ + "X = np.array([\n", + " [1, 2, 3, 4],\n", + " [5, 6, 7, 8],\n", + " [9, 10, 11, 12],\n", + " [13, 14, 15, 16]\n", + "])\n", + "\n", + "#X[:2][:2] wrong!\n", + "#X[0:2, 0:2]\n", + "X[:2, :2]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ys5NYp8erc7b" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy matrix, show the last two elements on the last two rows" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "iX53EZwurc7b" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "qJ8yC4Utrc7c" + }, + "outputs": [], + "source": [ + "X = np.array([\n", + " [1, 2, 3, 4],\n", + " [5, 6, 7, 8],\n", + " [9, 10, 11, 12],\n", + " [13, 14, 15, 16]\n", + "])\n", + "\n", + "X[2:, 2:]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "bwdc8Hb7rc7c" + }, + "source": [ + "![purple-divider](https://user-images.githubusercontent.com/7065401/52071927-c1cd7100-2562-11e9-908a-dde91ba14e59.png)\n", + "\n", + "## Array manipulation\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "cazSe8qorc7c" + }, + "source": [ + "### Convert the given integer numpy array to float" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "9PrXnyJ8rc7c" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "ikUrtCCWrc7d" + }, + "outputs": [], + "source": [ + "X = [-5, -3, 0, 10, 40]\n", + "\n", + "np.array(X, np.float)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "J-fjRh2erc7d" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Reverse the given numpy array (first element becomes last)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "K3T-Iqkxrc7d" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "pVxb3c-Brc7d" + }, + "outputs": [], + "source": [ + "X = [-5, -3, 0, 10, 40]\n", + "\n", + "X[::-1]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "cMPuEeEOrc7e" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Order (sort) the given numpy array" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "O9nphYpOrc7e" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "R2_apenlrc7e" + }, + "outputs": [], + "source": [ + "X = [0, 10, -5, 40, -3]\n", + "\n", + "X.sort()\n", + "X" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "jjS6ZALrrc7e" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy array, set the fifth element equal to 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "iWd7IyDerc7e" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "nRAWYAMqrc7f" + }, + "outputs": [], + "source": [ + "X = np.zeros(10)\n", + "\n", + "X[4] = 1\n", + "X" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "HA7eGmzSrc7f" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy array, change the 50 with a 40" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "DMnupB8Mrc7f" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "2rqpgTFgrc7f" + }, + "outputs": [], + "source": [ + "X = np.array([10, 20, 30, 50])\n", + "\n", + "X[3] = 40\n", + "X" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "zKzXzBsQrc7f" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy matrix, change the last row with all 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "HH5w2fryrc7g" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "FLRIom8qrc7g" + }, + "outputs": [], + "source": [ + "X = np.array([\n", + " [1, 2, 3, 4],\n", + " [5, 6, 7, 8],\n", + " [9, 10, 11, 12],\n", + " [13, 14, 15, 16]\n", + "])\n", + "\n", + "X[-1] = np.array([1, 1, 1, 1])\n", + "X" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "G1NsEu69rc7g" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy matrix, change the last item on the last row with a 0" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "HBgM-4_4rc7g" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "O5BE5z9Arc7h" + }, + "outputs": [], + "source": [ + "X = np.array([\n", + " [1, 2, 3, 4],\n", + " [5, 6, 7, 8],\n", + " [9, 10, 11, 12],\n", + " [13, 14, 15, 16]\n", + "])\n", + "\n", + "X[-1, -1] = 0\n", + "X" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ccsGbjSwrc7h" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy matrix, add 5 to every element" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "mldNTMf9rc7h" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "DAMpEKwwrc7i" + }, + "outputs": [], + "source": [ + "X = np.array([\n", + " [1, 2, 3, 4],\n", + " [5, 6, 7, 8],\n", + " [9, 10, 11, 12],\n", + " [13, 14, 15, 16]\n", + "])\n", + "\n", + "X + 5" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "3N04CKelrc7j" + }, + "source": [ + "![purple-divider](https://user-images.githubusercontent.com/7065401/52071927-c1cd7100-2562-11e9-908a-dde91ba14e59.png)\n", + "\n", + "## Boolean arrays _(also called masks)_\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "kFD_ly8lrc7j" + }, + "source": [ + "### Given the X numpy array, make a mask showing negative elements" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "fDIhsnvbrc7j" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "0elD1rftrc7j" + }, + "outputs": [], + "source": [ + "X = np.array([-1,2,0,-4,5,6,0,0,-9,10])\n", + "\n", + "mask = X <= 0\n", + "mask" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "TknJP2Murc7j" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy array, get the negative elements" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "xbS6MERbrc7k" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "AuHqPFegrc7k" + }, + "outputs": [], + "source": [ + "X = np.array([-1, 2, 0, -4, 5, 6, 0, 0, -9, 10])\n", + "\n", + "mask = X <= 0\n", + "X[mask]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Wnwb6JUjrc7k" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy array, get numbers higher than 5" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hkYNCf1Drc7k" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "jnNSZfABrc7l" + }, + "outputs": [], + "source": [ + "X = np.array([-1, 2, 0, -4, 5, 6, 0, 0, -9, 10])\n", + "\n", + "mask = X > 5\n", + "X[mask]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "b8rfb56Irc7q" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy array, get numbers higher than the elements mean" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "g4s42mTcrc7q" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "dtB5DJJVrc7r" + }, + "outputs": [], + "source": [ + "X = np.array([-1, 2, 0, -4, 5, 6, 0, 0, -9, 10])\n", + "\n", + "mask = X > X.mean()\n", + "X[mask]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "_YC2GlGTrc7r" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy array, get numbers equal to 2 or 10" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "KDZZjpLfrc7r" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "scrolled": true, + "id": "CB2woA7Crc7r" + }, + "outputs": [], + "source": [ + "X = np.array([-1, 2, 0, -4, 5, 6, 0, 0, -9, 10])\n", + "\n", + "mask = (X == 2) | (X == 10)\n", + "X[mask]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "uICW0aierc7r" + }, + "source": [ + "![purple-divider](https://user-images.githubusercontent.com/7065401/52071927-c1cd7100-2562-11e9-908a-dde91ba14e59.png)\n", + "\n", + "## Logic functions\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "EMRJGES4rc7s" + }, + "source": [ + "### Given the X numpy array, return True if none of its elements is zero" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "28t2nSNOrc7s" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "i7ST0barrc7s" + }, + "outputs": [], + "source": [ + "X = np.array([-1, 2, 0, -4, 5, 6, 0, 0, -9, 10])\n", + "\n", + "X.all()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ZllMBs05rc7s" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy array, return True if any of its elements is zero" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "0R6V8CbXrc7s" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "MnSgcU93rc7s" + }, + "outputs": [], + "source": [ + "X = np.array([-1, 2, 0, -4, 5, 6, 0, 0, -9, 10])\n", + "\n", + "X.any()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "j8pkKkPWrc7s" + }, + "source": [ + "![purple-divider](https://user-images.githubusercontent.com/7065401/52071927-c1cd7100-2562-11e9-908a-dde91ba14e59.png)\n", + "\n", + "## Summary statistics" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "m6D9TKzVrc7t" + }, + "source": [ + "### Given the X numpy array, show the sum of its elements" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "DBO_qoJLrc7t" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "6pCCCvuQrc7t" + }, + "outputs": [], + "source": [ + "X = np.array([3, 5, 6, 7, 2, 3, 4, 9, 4])\n", + "\n", + "#np.sum(X)\n", + "X.sum()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "57H0seHArc7t" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy array, show the mean value of its elements" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "wMaDGblDrc7t" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "d8xhWBDsrc7u" + }, + "outputs": [], + "source": [ + "X = np.array([1, 2, 0, 4, 5, 6, 0, 0, 9, 10])\n", + "\n", + "#np.mean(X)\n", + "X.mean()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7yEwKyxorc7u" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy matrix, show the sum of its columns" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "xJl5kmvFrc7u" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "vKPc7-Eirc7u" + }, + "outputs": [], + "source": [ + "X = np.array([\n", + " [1, 2, 3, 4],\n", + " [5, 6, 7, 8],\n", + " [9, 10, 11, 12],\n", + " [13, 14, 15, 16]\n", + "])\n", + "\n", + "X.sum(axis=0) # remember: axis=0 columns; axis=1 rows" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "UDeyYrcgrc7v" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy matrix, show the mean value of its rows" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "65D32Uv9rc7v" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "ElllkIJRrc7v" + }, + "outputs": [], + "source": [ + "X = np.array([\n", + " [1, 2, 3, 4],\n", + " [5, 6, 7, 8],\n", + " [9, 10, 11, 12],\n", + " [13, 14, 15, 16]\n", + "])\n", + "\n", + "X.mean(axis=1) # remember: axis=0 columns; axis=1 rows" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4giIPYj9rc7v" + }, + "source": [ + "![green-divider](https://user-images.githubusercontent.com/7065401/52071924-c003ad80-2562-11e9-8297-1c6595f8a7ff.png)\n", + "\n", + "### Given the X numpy array, show the max value of its elements" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "SQpzeUSUrc7v" + }, + "outputs": [], + "source": [ + "# your code goes here\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cell_type": "solution", + "id": "M5UOzVLerc7v" + }, + "outputs": [], + "source": [ + "X = np.array([1, 2, 0, 4, 5, 6, 0, 0, 9, 10])\n", + "\n", + "#np.max(X)\n", + "X.max()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "P2xy1E4Crc7w" + }, + "source": [ + "![purple-divider](https://user-images.githubusercontent.com/7065401/52071927-c1cd7100-2562-11e9-908a-dde91ba14e59.png)" + ] + } + ], + "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.4" + }, + "colab": { + "provenance": [] + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file