diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 46f5aa14..b6c7f0c3 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -16,11 +16,11 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "import numpy as np\n" ] }, { @@ -34,11 +34,103 @@ }, { "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n" + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.26.4\n", + "Build Dependencies:\n", + " blas:\n", + " detection method: pkgconfig\n", + " found: true\n", + " include directory: /opt/anaconda3/include\n", + " lib directory: /opt/anaconda3/lib\n", + " name: openblas\n", + " openblas configuration: USE_64BITINT= DYNAMIC_ARCH=1 DYNAMIC_OLDER= NO_CBLAS=\n", + " NO_LAPACK=0 NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP=0 VORTEX MAX_THREADS=128\n", + " pc file directory: /opt/anaconda3/lib/pkgconfig\n", + " version: 0.3.21\n", + " lapack:\n", + " detection method: internal\n", + " found: true\n", + " include directory: unknown\n", + " lib directory: unknown\n", + " name: dep4347739648\n", + " openblas configuration: unknown\n", + " pc file directory: unknown\n", + " version: 1.26.4\n", + "Compilers:\n", + " c:\n", + " args: -ftree-vectorize, -fPIC, -fPIE, -fstack-protector-strong, -O2, -pipe, -isystem,\n", + " /opt/anaconda3/include, -fdebug-prefix-map=/var/folders/k1/30mswbxs7r1g6zwn8y4fyt500000gp/T/abs_a51i_mbs7m/croot/numpy_and_numpy_base_1708638620867/work=/usr/local/src/conda/numpy-base-1.26.4,\n", + " -fdebug-prefix-map=/opt/anaconda3=/usr/local/src/conda-prefix, -D_FORTIFY_SOURCE=2,\n", + " -isystem, /opt/anaconda3/include, -mmacosx-version-min=11.1\n", + " commands: arm64-apple-darwin20.0.0-clang\n", + " linker: ld64\n", + " linker args: -Wl,-pie, -Wl,-headerpad_max_install_names, -Wl,-dead_strip_dylibs,\n", + " -Wl,-rpath,/opt/anaconda3/lib, -L/opt/anaconda3/lib, -ftree-vectorize, -fPIC,\n", + " -fPIE, -fstack-protector-strong, -O2, -pipe, -isystem, /opt/anaconda3/include,\n", + " -fdebug-prefix-map=/var/folders/k1/30mswbxs7r1g6zwn8y4fyt500000gp/T/abs_a51i_mbs7m/croot/numpy_and_numpy_base_1708638620867/work=/usr/local/src/conda/numpy-base-1.26.4,\n", + " -fdebug-prefix-map=/opt/anaconda3=/usr/local/src/conda-prefix, -D_FORTIFY_SOURCE=2,\n", + " -isystem, /opt/anaconda3/include, -mmacosx-version-min=11.1\n", + " name: clang\n", + " version: 14.0.6\n", + " c++:\n", + " args: -ftree-vectorize, -fPIC, -fPIE, -fstack-protector-strong, -O2, -pipe, -stdlib=libc++,\n", + " -fvisibility-inlines-hidden, -fmessage-length=0, -isystem, /opt/anaconda3/include,\n", + " -fdebug-prefix-map=/var/folders/k1/30mswbxs7r1g6zwn8y4fyt500000gp/T/abs_a51i_mbs7m/croot/numpy_and_numpy_base_1708638620867/work=/usr/local/src/conda/numpy-base-1.26.4,\n", + " -fdebug-prefix-map=/opt/anaconda3=/usr/local/src/conda-prefix, -D_FORTIFY_SOURCE=2,\n", + " -isystem, /opt/anaconda3/include, -mmacosx-version-min=11.1\n", + " commands: arm64-apple-darwin20.0.0-clang++\n", + " linker: ld64\n", + " linker args: -Wl,-pie, -Wl,-headerpad_max_install_names, -Wl,-dead_strip_dylibs,\n", + " -Wl,-rpath,/opt/anaconda3/lib, -L/opt/anaconda3/lib, -ftree-vectorize, -fPIC,\n", + " -fPIE, -fstack-protector-strong, -O2, -pipe, -stdlib=libc++, -fvisibility-inlines-hidden,\n", + " -fmessage-length=0, -isystem, /opt/anaconda3/include, -fdebug-prefix-map=/var/folders/k1/30mswbxs7r1g6zwn8y4fyt500000gp/T/abs_a51i_mbs7m/croot/numpy_and_numpy_base_1708638620867/work=/usr/local/src/conda/numpy-base-1.26.4,\n", + " -fdebug-prefix-map=/opt/anaconda3=/usr/local/src/conda-prefix, -D_FORTIFY_SOURCE=2,\n", + " -isystem, /opt/anaconda3/include, -mmacosx-version-min=11.1\n", + " name: clang\n", + " version: 14.0.6\n", + " cython:\n", + " commands: cython\n", + " linker: cython\n", + " name: cython\n", + " version: 3.0.8\n", + "Machine Information:\n", + " build:\n", + " cpu: aarch64\n", + " endian: little\n", + " family: aarch64\n", + " system: darwin\n", + " host:\n", + " cpu: aarch64\n", + " endian: little\n", + " family: aarch64\n", + " system: darwin\n", + "Python Information:\n", + " path: /opt/anaconda3/bin/python\n", + " version: '3.12'\n", + "SIMD Extensions:\n", + " baseline:\n", + " - NEON\n", + " - NEON_FP16\n", + " - NEON_VFPV4\n", + " - ASIMD\n", + " found:\n", + " - ASIMDHP\n", + " not found:\n", + " - ASIMDFHM\n", + "\n", + "None\n" + ] + } + ], + "source": [ + "print(np.__version__)\n", + "print(np.show_config())" ] }, { @@ -51,11 +143,11 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "a = np.random.randint(0, 10, size=(2,3,5))" ] }, { @@ -68,11 +160,25 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[6 6 3 9 8]\n", + " [1 8 2 6 1]\n", + " [1 2 1 8 1]]\n", + "\n", + " [[2 8 1 4 1]\n", + " [0 0 5 7 0]\n", + " [8 2 0 8 6]]]\n" + ] + } + ], "source": [ - "### [your code here]\n" + "print(a)" ] }, { @@ -85,11 +191,11 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "b = np.ones((5,2,3))" ] }, { @@ -102,11 +208,32 @@ }, { "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n" + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]\n", + " [1. 1. 1.]]]\n" + ] + } + ], + "source": [ + "print(b)" ] }, { @@ -119,11 +246,25 @@ }, { "cell_type": "code", - "execution_count": 25, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n" + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "def checkSizes(a: np.dtype, b: np.dtype):\n", + " if a.ndim == b.ndim:\n", + " return True\n", + " else:\n", + " return False\n", + "\n", + "print(checkSizes(a, b))" ] }, { @@ -135,12 +276,10 @@ ] }, { - "cell_type": "code", - "execution_count": 26, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "### [your code here]\n" + "We can't because both matrices do not have the same shape (a has 2,3,5 and b has 5,2,3)" ] }, { @@ -154,11 +293,26 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[1. 1. 1. 1. 1.]\n", + " [1. 1. 1. 1. 1.]\n", + " [1. 1. 1. 1. 1.]]\n", + "\n", + " [[1. 1. 1. 1. 1.]\n", + " [1. 1. 1. 1. 1.]\n", + " [1. 1. 1. 1. 1.]]]\n" + ] + } + ], "source": [ - "### [your code here]\n" + "c = b.reshape(2,3,5)\n", + "print(c)" ] }, { @@ -171,11 +325,33 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[ 7. 7. 4. 10. 9.]\n", + " [ 2. 9. 3. 7. 2.]\n", + " [ 2. 3. 2. 9. 2.]]\n", + "\n", + " [[ 3. 9. 2. 5. 2.]\n", + " [ 1. 1. 6. 8. 1.]\n", + " [ 9. 3. 1. 9. 7.]]]\n" + ] + } + ], "source": [ - "### [your code here]\n" + "d = a + c\n", + "print(d)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now it works because both matrices have the same shape (2,3,5)" ] }, { @@ -188,12 +364,40 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[6 6 3 9 8]\n", + " [1 8 2 6 1]\n", + " [1 2 1 8 1]]\n", + "\n", + " [[2 8 1 4 1]\n", + " [0 0 5 7 0]\n", + " [8 2 0 8 6]]]\n", + "[[[ 7. 7. 4. 10. 9.]\n", + " [ 2. 9. 3. 7. 2.]\n", + " [ 2. 3. 2. 9. 2.]]\n", + "\n", + " [[ 3. 9. 2. 5. 2.]\n", + " [ 1. 1. 6. 8. 1.]\n", + " [ 9. 3. 1. 9. 7.]]]\n" + ] + } + ], + "source": [ + "print(a)\n", + "print(d)\n" + ] + }, + { + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "### [your code here]\n", - "\n" + "The difference comes from the fact that a is a matrix of random integers, while d is the result of adding a + c" ] }, { @@ -206,11 +410,26 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[6. 6. 3. 9. 8.]\n", + " [1. 8. 2. 6. 1.]\n", + " [1. 2. 1. 8. 1.]]\n", + "\n", + " [[2. 8. 1. 4. 1.]\n", + " [0. 0. 5. 7. 0.]\n", + " [8. 2. 0. 8. 6.]]]\n" + ] + } + ], "source": [ - "### [your code here]\n" + "e = a * c\n", + "print(e)" ] }, { @@ -224,12 +443,26 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], "source": [ - "### [your code here]\n", - "\n" + "print(np.array_equal(a, e))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "They are both equal because c is a matrix of 1s, so multiplying any number with 1 is gonna return the same number." ] }, { @@ -243,12 +476,23 @@ }, { "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n", - "\n" + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "d_max is 10.0, d_min is 1.0, and d_mean is 4.833333333333333\n" + ] + } + ], + "source": [ + "d_max = np.max(d)\n", + "d_min = np.min(d)\n", + "d_mean = np.mean(d)\n", + "\n", + "print(f\"d_max is {d_max}, d_min is {d_min}, and d_mean is {d_mean}\")" ] }, { @@ -261,11 +505,26 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[6. 6. 3. 9. 8.]\n", + " [1. 8. 2. 6. 1.]\n", + " [1. 2. 1. 8. 1.]]\n", + "\n", + " [[2. 8. 1. 4. 1.]\n", + " [0. 0. 5. 7. 0.]\n", + " [8. 2. 0. 8. 6.]]]\n" + ] + } + ], "source": [ - "### [your code here]\n" + "f = np.empty((2, 3, 5))\n", + "print(f)" ] }, { @@ -287,11 +546,40 @@ }, { "cell_type": "code", - "execution_count": 34, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n" + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[ 75. 75. 25. 100. 75.]\n", + " [ 25. 75. 25. 75. 25.]\n", + " [ 25. 25. 25. 75. 25.]]\n", + "\n", + " [[ 25. 75. 25. 75. 25.]\n", + " [ 0. 0. 75. 75. 0.]\n", + " [ 75. 25. 0. 75. 75.]]]\n" + ] + } + ], + "source": [ + "for i in range(d.shape[0]):\n", + " for j in range(d.shape[1]):\n", + " for k in range(d.shape[2]):\n", + " val = d[i][j][k]\n", + " if val == d_min:\n", + " f[i][j][k] = 0\n", + " elif val == d_max:\n", + " f[i][j][k] = 100\n", + " elif val == d_mean:\n", + " f[i][j][k] = 50\n", + " elif d_min < val < d_mean:\n", + " f[i][j][k] = 25\n", + " elif d_mean < val < d_max:\n", + " f[i][j][k] = 75\n", + " \n", + "print(f)" ] }, { @@ -325,11 +613,35 @@ }, { "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n" + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Array d is\n", + " [[[ 7. 7. 4. 10. 9.]\n", + " [ 2. 9. 3. 7. 2.]\n", + " [ 2. 3. 2. 9. 2.]]\n", + "\n", + " [[ 3. 9. 2. 5. 2.]\n", + " [ 1. 1. 6. 8. 1.]\n", + " [ 9. 3. 1. 9. 7.]]]\n", + "Array f is \n", + " [[[ 75. 75. 25. 100. 75.]\n", + " [ 25. 75. 25. 75. 25.]\n", + " [ 25. 25. 25. 75. 25.]]\n", + "\n", + " [[ 25. 75. 25. 75. 25.]\n", + " [ 0. 0. 75. 75. 0.]\n", + " [ 75. 25. 0. 75. 75.]]]\n" + ] + } + ], + "source": [ + "print(\"Array d is\\n\", d)\n", + "print(\"Array f is \\n\", f)" ] }, { @@ -350,17 +662,46 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[['D' 'D' 'D' 'B' 'D']\n", + " ['D' 'D' 'B' 'B' 'B']\n", + " ['D' 'B' 'D' 'D' 'D']]\n", + "\n", + " [['B' 'B' 'B' 'B' 'E']\n", + " ['D' 'D' 'D' 'D' 'D']\n", + " ['B' 'D' 'A' 'D' 'D']]]\n" + ] + } + ], + "source": [ + "f = np.array([[[ 'D', 'D', 'D', 'B', 'D'],\n", + " [ 'D', 'D', 'B', 'B', 'B'],\n", + " [ 'D', 'B', 'D', 'D', 'D']],\n", + "\n", + " [[ 'B', 'B', 'B', 'B', 'E'],\n", + " [ 'D', 'D', 'D', 'D', 'D'],\n", + " [ 'B', 'D', 'A', 'D', 'D']]])\n", + "\n", + "print(f)" + ] + }, + { + "cell_type": "code", + "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "### [your code here]" - ] + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "base", "language": "python", "name": "python3" }, @@ -374,7 +715,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.0" + "version": "3.12.7" } }, "nbformat": 4,