From d603ac04f678e680e6cc274ff74091bf8a4ec7de Mon Sep 17 00:00:00 2001 From: chukseey Date: Thu, 21 Apr 2022 15:17:15 +0100 Subject: [PATCH] lab done --- your-code/main (1).ipynb | 838 +++++++++++++++++++++++++++++++++++++++ your-code/main.ipynb | 127 +++++- 2 files changed, 947 insertions(+), 18 deletions(-) create mode 100644 your-code/main (1).ipynb diff --git a/your-code/main (1).ipynb b/your-code/main (1).ipynb new file mode 100644 index 0000000..1caecb8 --- /dev/null +++ b/your-code/main (1).ipynb @@ -0,0 +1,838 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "_Fxq8Hi_KG0b" + }, + "source": [ + "# Intrduction to NumPy\n", + "\n", + "\n", + "#### 1. Import NumPy under the name np." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "ubrB9owaKG0d" + }, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Z5cDqtw4KG0f" + }, + "source": [ + "#### 2. Print your NumPy version." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "xTNJxTarKG0g", + "outputId": "56de92ee-d2c4-4a89-f0e0-99ba429471c8", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'1.21.6'" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 2 + } + ], + "source": [ + "np.__version__" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "GqbhrutEKG0i" + }, + "source": [ + "#### 3. Generate a 2x3x5 3-dimensional array with random values. Assign the array to variable *a*.\n", + "**Challenge**: there are at least three easy ways that use numpy to generate random arrays. How many ways can you find?" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "id": "67XDGpXcKG0i" + }, + "outputs": [], + "source": [ + "# Method \n", + "a = np.random.rand(2, 3, 5)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "id": "grWwi_QtKG0j" + }, + "outputs": [], + "source": [ + "# Method 2\n", + "a = np.random.randn(2, 3, 5)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "id": "fXZWTslJKG0l" + }, + "outputs": [], + "source": [ + "# Method 3\n", + "a = np.random.randint(1, 99, size=(2, 3, 5))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "sMoh3yUEKG0m" + }, + "source": [ + "#### 4. Print *a*.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "id": "lrHt_CS5KG0m", + "outputId": "cae9a0da-9c5f-4dd9-b3d3-85be03d90682", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[[62 78 10 63 39]\n", + " [64 3 98 58 49]\n", + " [65 20 88 92 60]]\n", + "\n", + " [[64 11 30 72 21]\n", + " [49 45 40 48 41]\n", + " [73 73 43 32 14]]]\n" + ] + } + ], + "source": [ + "# your code here\n", + "print(a)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5Bja2MXiKG0n" + }, + "source": [ + "#### 5. Create a 5x2x3 3-dimensional array with all values equaling 1. Assign the array to variable *b*." + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": { + "id": "Y0G13F-CKG0o" + }, + "outputs": [], + "source": [ + "# your code here \n", + "b = np.ones((5, 3, 2))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "PXH1q_7HKG0p" + }, + "source": [ + "#### 6. Print *b*.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "id": "dPIx-z5SKG0q", + "outputId": "93dc8eba-8580-48a6-914e-9b1b9a2e479f", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[[1. 1.]\n", + " [1. 1.]\n", + " [1. 1.]]\n", + "\n", + " [[1. 1.]\n", + " [1. 1.]\n", + " [1. 1.]]\n", + "\n", + " [[1. 1.]\n", + " [1. 1.]\n", + " [1. 1.]]\n", + "\n", + " [[1. 1.]\n", + " [1. 1.]\n", + " [1. 1.]]\n", + "\n", + " [[1. 1.]\n", + " [1. 1.]\n", + " [1. 1.]]]\n" + ] + } + ], + "source": [ + "print(b)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "JJRo3Zc6KG0r" + }, + "source": [ + "#### 7. Do *a* and *b* have the same size? How do you prove that in Python code?" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": { + "id": "vpnr1YeNKG0r", + "outputId": "ccf26510-a0dd-427e-c4fc-14b6e81c91b8", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "True" + ] + }, + "metadata": {}, + "execution_count": 37 + } + ], + "source": [ + "# your code here\n", + "a.size == b.size" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "YDnc6-xYKG0s" + }, + "source": [ + "#### 8. Are you able to add *a* and *b*? Why or why not?\n" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": { + "id": "OWHritaoKG0s", + "outputId": "b9b8c343-465e-43f7-d3b2-597697b4c240", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "The shape of a is: (2, 3, 5)\n", + "The shape of b is: (5, 3, 2)\n" + ] + } + ], + "source": [ + "# your answer here\n", + "print(\"The shape of a is: \", a.shape)\n", + "print(\"The shape of b is: \", b.shape)" + ] + }, + { + "cell_type": "code", + "source": [ + "a+b" + ], + "metadata": { + "id": "c3wxoxM-PZ68", + "outputId": "ca4377b8-b855-491d-d1c2-aef0df8883f1", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 168 + } + }, + "execution_count": 39, + "outputs": [ + { + "output_type": "error", + "ename": "ValueError", + "evalue": "ignored", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0ma\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mValueError\u001b[0m: operands could not be broadcast together with shapes (2,3,5) (5,3,2) " + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "As we can see the shape of both the arrays are different so we can not braodcast on each other, and hence addition operator isn't working." + ], + "metadata": { + "id": "k7kC47IpPdn9" + } + }, + { + "cell_type": "markdown", + "metadata": { + "id": "j12r7L5xKG0t" + }, + "source": [ + "#### 9. Transpose *b* so that it has the same structure of *a* (i.e. become a 2x3x5 array). Assign the transposed array to variable *c*." + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": { + "id": "_bC8atF7KG0t" + }, + "outputs": [], + "source": [ + "# your code here\n", + "c = b.T" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "LYrsZ4c_KG0t" + }, + "source": [ + "#### 10. Try to add *a* and *c*. Now it should work. Assign the sum to variable *d*. But why does it work now?" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": { + "id": "lD2nDi-YKG0u", + "outputId": "37deca4f-eb7e-4e97-960a-a9264b0333f3", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "The shape of a is: (2, 3, 5)\n", + "The shape of c is: (2, 3, 5)\n" + ] + } + ], + "source": [ + "# your code/answer here\n", + "# your answer here\n", + "print(\"The shape of a is: \", a.shape)\n", + "print(\"The shape of c is: \", c.shape)" + ] + }, + { + "cell_type": "code", + "source": [ + "d = a+c" + ], + "metadata": { + "id": "ewRWVnLJQOx1" + }, + "execution_count": 44, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "As we can see the shape of both 'a' and 'c' are same so we can easily broadcast on each other and, hence are able to perform addition." + ], + "metadata": { + "id": "IljkvcqzQQia" + } + }, + { + "cell_type": "markdown", + "metadata": { + "id": "y9Rq6bC2KG0u" + }, + "source": [ + "#### 11. Print *a* and *d*. Notice the difference and relation of the two array in terms of the values? Explain." + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": { + "id": "FCYi47EDKG0v", + "outputId": "8dd866ec-c807-423b-d72e-d1a868d7389f", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[[62 78 10 63 39]\n", + " [64 3 98 58 49]\n", + " [65 20 88 92 60]]\n", + "\n", + " [[64 11 30 72 21]\n", + " [49 45 40 48 41]\n", + " [73 73 43 32 14]]]\n" + ] + } + ], + "source": [ + "# your code/answer here\n", + "print(a)" + ] + }, + { + "cell_type": "code", + "source": [ + "print(d)" + ], + "metadata": { + "id": "In_wD8VEQ51E", + "outputId": "79590597-605c-449c-c244-33bdd476d61b", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": 46, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[[63. 79. 11. 64. 40.]\n", + " [65. 4. 99. 59. 50.]\n", + " [66. 21. 89. 93. 61.]]\n", + "\n", + " [[65. 12. 31. 73. 22.]\n", + " [50. 46. 41. 49. 42.]\n", + " [74. 74. 44. 33. 15.]]]\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "As can be seen clearly that the values in array 'd' is one more than the value of a" + ], + "metadata": { + "id": "DMlBZkdRQ-Mo" + } + }, + { + "cell_type": "markdown", + "metadata": { + "id": "gJmodD9yKG0v" + }, + "source": [ + "#### 12. Multiply *a* and *c*. Assign the result to *e*." + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": { + "id": "xUQTn_mGKG0w", + "outputId": "4e2c0901-4b8d-4a1f-8e68-4eecabf2dc34", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[[62. 78. 10. 63. 39.]\n", + " [64. 3. 98. 58. 49.]\n", + " [65. 20. 88. 92. 60.]]\n", + "\n", + " [[64. 11. 30. 72. 21.]\n", + " [49. 45. 40. 48. 41.]\n", + " [73. 73. 43. 32. 14.]]]\n" + ] + } + ], + "source": [ + "# your code here\n", + "e = a*c\n", + "print(e)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "qO3ZVv7RKG0w" + }, + "source": [ + "#### 13. Does *e* equal to *a*? Why or why not?\n" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": { + "id": "hvrcKzuFKG0w", + "outputId": "2fc5dca2-0481-4248-b286-e659db0b8693", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[[ True True True True True]\n", + " [ True True True True True]\n", + " [ True True True True True]]\n", + "\n", + " [[ True True True True True]\n", + " [ True True True True True]\n", + " [ True True True True True]]]\n" + ] + } + ], + "source": [ + "# your code/answer here\n", + "print(e == a)" + ] + }, + { + "cell_type": "markdown", + "source": [ + "Yes 'e' is equal to 'a' and as can be seen when did e==a we can see True at all the places." + ], + "metadata": { + "id": "58TIZfUWRbv_" + } + }, + { + "cell_type": "markdown", + "metadata": { + "id": "l6PDMOkDKG0x" + }, + "source": [ + "#### 14. Identify the max, min, and mean values in *d*. Assign those values to variables *d_max*, *d_min* and *d_mean*." + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": { + "id": "S7HoUoHvKG0y" + }, + "outputs": [], + "source": [ + "# your code here\n", + "d_max = np.max(d)\n", + "d_min = np.min(d)\n", + "d_mean = np.mean(d)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "3YqW9T2cKG0y" + }, + "source": [ + "#### 15. Now we want to label the values in *d*. First create an empty array *f* with the same shape (i.e. 2x3x5) as *d* using `np.empty`.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": { + "id": "ZyR9IUK2KG0z" + }, + "outputs": [], + "source": [ + "# your code here\n", + "f = np.empty(shape=(2,3,5))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "9p2Z1xjYKG00" + }, + "source": [ + "#### 16. Populate the values in *f*. \n", + "\n", + "For each value in *d*, if it's larger than *d_min* but smaller than *d_mean*, assign 25 to the corresponding value in *f*. If a value in *d* is larger than *d_mean* but smaller than *d_max*, assign 75 to the corresponding value in *f*. If a value equals to *d_mean*, assign 50 to the corresponding value in *f*. Assign 0 to the corresponding value(s) in *f* for *d_min* in *d*. Assign 100 to the corresponding value(s) in *f* for *d_max* in *d*. In the end, f should have only the following values: 0, 25, 50, 75, and 100.\n", + "\n", + "**Note**: you don't have to use Numpy in this question." + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": { + "id": "RNDOCu2rKG00" + }, + "outputs": [], + "source": [ + "# your code here\n", + "for i in range(2):\n", + " for j in range(3):\n", + " for k in range(5):\n", + " if d[i, j, k] > d_min and d[i, j, k] < d_mean:\n", + " f[i, j, k] = 25\n", + " elif d[i, j, k] > d_mean and d[i, j, k] < d_max:\n", + " f[i, j, k] = 75\n", + " elif d[i, j, k] == d_mean:\n", + " f[i, j, k] = 50\n", + " elif d[i, j, k] == d_min:\n", + " f[i, j, k] = 0\n", + " elif d[i, j, k] == d_max:\n", + " f[i, j, k] = 100" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "jzeFoChLKG00" + }, + "source": [ + "#### 17. Print *d* and *f*. Do you have your expected *f*?\n", + "For instance, if your *d* is:\n", + "```python\n", + "[[[1.85836099, 1.67064465, 1.62576044, 1.40243961, 1.88454931],\n", + "[1.75354326, 1.69403643, 1.36729252, 1.61415071, 1.12104981],\n", + "[1.72201435, 1.1862918 , 1.87078449, 1.7726778 , 1.88180042]],\n", + "[[1.44747908, 1.31673383, 1.02000951, 1.52218947, 1.97066381],\n", + "[1.79129243, 1.74983003, 1.96028037, 1.85166831, 1.65450881],\n", + "[1.18068344, 1.9587381 , 1.00656599, 1.93402165, 1.73514584]]]\n", + "```\n", + "Your *f* should be:\n", + "```python\n", + "[[[ 75., 75., 75., 25., 75.],\n", + "[ 75., 75., 25., 25., 25.],\n", + "[ 75., 25., 75., 75., 75.]],\n", + "[[ 25., 25., 25., 25., 100.],\n", + "[ 75., 75., 75., 75., 75.],\n", + "[ 25., 75., 0., 75., 75.]]]\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": { + "id": "AqtWXO7EKG01", + "outputId": "296533fc-1971-4c16-8361-14e97c7617fa", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[[63. 79. 11. 64. 40.]\n", + " [65. 4. 99. 59. 50.]\n", + " [66. 21. 89. 93. 61.]]\n", + "\n", + " [[65. 12. 31. 73. 22.]\n", + " [50. 46. 41. 49. 42.]\n", + " [74. 74. 44. 33. 15.]]]\n" + ] + } + ], + "source": [ + "# your code here\n", + "print(d)" + ] + }, + { + "cell_type": "code", + "source": [ + "print(f)" + ], + "metadata": { + "id": "PVXWzpYfTqUv", + "outputId": "49e59249-60a2-4645-c294-f58da72febf1", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": 66, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[[ 75. 75. 25. 75. 25.]\n", + " [ 75. 0. 100. 75. 25.]\n", + " [ 75. 25. 75. 75. 75.]]\n", + "\n", + " [[ 75. 25. 25. 75. 25.]\n", + " [ 25. 25. 25. 25. 25.]\n", + " [ 75. 75. 25. 25. 25.]]]\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "wL_Ni68NKG01" + }, + "source": [ + "#### 18. Bonus question: instead of using numbers (i.e. 0, 25, 50, 75, and 100), use string values (\"A\", \"B\", \"C\", \"D\", and \"E\") to label the array elements. For the example above, the expected result is:\n", + "\n", + "```python\n", + "[[[ 'D', 'D', 'D', 'B', 'D'],\n", + "[ 'D', 'D', 'B', 'B', 'B'],\n", + "[ 'D', 'B', 'D', 'D', 'D']],\n", + "[[ 'B', 'B', 'B', 'B', 'E'],\n", + "[ 'D', 'D', 'D', 'D', 'D'],\n", + "[ 'B', 'D', 'A', 'D', 'D']]]\n", + "```\n", + "**Note**: you don't have to use Numpy in this question." + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": { + "id": "1j3-cFf9KG02" + }, + "outputs": [], + "source": [ + "# your code here\n", + "f = f.astype(int)\n", + "f = f.astype(str)\n", + "for i in range(2):\n", + " for j in range(3):\n", + " for k in range(5):\n", + " if f[i, j, k] == '0':\n", + " f[i, j, k] = 'A'\n", + " elif f[i, j, k] == '25':\n", + " f[i, j, k] = 'B'\n", + " elif f[i, j, k] == '50':\n", + " f[i, j, k] = 'C'\n", + " elif f[i, j, k] == '75':\n", + " f[i, j, k] = 'D'\n", + " elif f[i, j, k] == '100':\n", + " f[i, j, k] = 'E'" + ] + }, + { + "cell_type": "code", + "source": [ + "print(f)" + ], + "metadata": { + "id": "erpLbgy3T8TJ", + "outputId": "5583d240-51af-43e1-a722-0b5fe0c69345", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": 68, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[['D' 'D' 'B' 'D' 'B']\n", + " ['D' 'A' 'E' 'D' 'B']\n", + " ['D' 'B' 'D' 'D' 'D']]\n", + "\n", + " [['D' 'B' 'B' 'D' 'B']\n", + " ['B' 'B' 'B' 'B' 'B']\n", + " ['D' 'D' 'B' 'B' 'B']]]\n" + ] + } + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.9.7" + }, + "colab": { + "name": "main.ipynb", + "provenance": [] + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file diff --git a/your-code/main.ipynb b/your-code/main.ipynb index e66d6ce..b86dfb1 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -12,11 +12,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "import numpy as np" ] }, { @@ -28,11 +28,43 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'1.20.3'" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "np.__version__" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "'numpy.ndarray' object is not callable", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/var/folders/ln/93q25qtx3d5d6fz7gqt026dr0000gn/T/ipykernel_33829/750741062.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mA\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m20\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m30\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m40\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m: 'numpy.ndarray' object is not callable" + ] + } + ], + "source": [ + "np.random.rand(3,2)\n" ] }, { @@ -45,20 +77,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[0.30831876, 0.24512215],\n", + " [0.34967371, 0.98603722],\n", + " [0.54278182, 0.92545894]])" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Method 1" + "# Method \n", + "np.random.rand(3,2)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "TypeError", + "evalue": "'numpy.ndarray' object is not callable", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/var/folders/ln/93q25qtx3d5d6fz7gqt026dr0000gn/T/ipykernel_33829/3017039884.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Method 2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mA\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m: 'numpy.ndarray' object is not callable" + ] + } + ], "source": [ - "# Method 2" + "# Method 2\n" ] }, { @@ -95,11 +153,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here \n", + "A = np.arange(10,20,2)\n", + "b = 1 \n" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" ] }, { @@ -111,11 +191,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "b\n" ] }, { @@ -345,7 +436,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -359,7 +450,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.9.7" } }, "nbformat": 4,