diff --git a/your-code/main.ipynb b/your-code/main.ipynb index e66d6ce..5fa662b 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -12,11 +12,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "import numpy as np" ] }, { @@ -28,11 +28,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.21.3\n" + ] + } + ], "source": [ - "# your code here" + "print(np.__version__)" ] }, { @@ -45,25 +53,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 60, "metadata": {}, "outputs": [], "source": [ - "# Method 1" + "a = np.random.random((2,3,5))" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Method 2" + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[0.58194864, 0.11779508, 0.05794394, 0.26487818, 0.77850334],\n", + " [0.3019015 , 0.43638105, 0.56183575, 0.45443148, 0.55599933],\n", + " [0.04484864, 0.9635898 , 0.96114469, 0.77186384, 0.97303719]],\n", + "\n", + " [[0.78909794, 0.82373608, 0.95600263, 0.48596983, 0.61589573],\n", + " [0.7920134 , 0.35455778, 0.68215307, 0.06960897, 0.3098152 ],\n", + " [0.42808914, 0.98397529, 0.90762971, 0.42373902, 0.44653298]]])" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.random.random(size = (2,3,5))" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 62, "metadata": {}, "outputs": [], "source": [ @@ -79,11 +104,54 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[0.88223541, 0.99657168, 0.3853152 , 0.12310601, 0.48196487],\n", + " [0.50645512, 0.45441129, 0.99766545, 0.01527978, 0.74056455],\n", + " [0.89252294, 0.85672339, 0.40971228, 0.88408338, 0.12032061]],\n", + "\n", + " [[0.83952757, 0.18767728, 0.20872664, 0.13426983, 0.49856332],\n", + " [0.67536136, 0.2492708 , 0.74735713, 0.3308693 , 0.79295865],\n", + " [0.09005245, 0.78621685, 0.48210981, 0.3134594 , 0.76338164]]])" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[3, 3, 3, 3, 3],\n", + " [3, 3, 3, 3, 3],\n", + " [3, 3, 3, 3, 3]],\n", + "\n", + " [[3, 3, 3, 3, 3],\n", + " [3, 3, 3, 3, 3],\n", + " [3, 3, 3, 3, 3]]])" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "d" ] }, { @@ -95,11 +163,36 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[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]]])" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b = np.zeros(shape=(5,2,3), dtype = int) +1\n", + "b" ] }, { @@ -111,7 +204,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 66, "metadata": {}, "outputs": [], "source": [ @@ -127,11 +220,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 67, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "len(a) == len(b)" ] }, { @@ -143,11 +247,27 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your answer here" + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "operands could not be broadcast together with shapes (2,3,5) (5,2,3) (2,3,5) ", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/var/folders/bx/4mbq6kdx7yq1jqkn_7345mqc0000gn/T/ipykernel_18860/148979724.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcopy\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[0;32m----> 2\u001b[0;31m \u001b[0mc\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\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[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;31m# No we can't beacause they are from different size\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mValueError\u001b[0m: operands could not be broadcast together with shapes (2,3,5) (5,2,3) (2,3,5) " + ] + } + ], + "source": [ + "c = a.copy()\n", + "c[:len(b)] += b\n", + "\n", + "\n", + "# No we can't beacause they are from different size " ] }, { @@ -159,11 +279,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[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]]])" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c = b.reshape(2,3,5)\n", + "c" ] }, { @@ -175,11 +313,30 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code/answer here" + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[1.88223541, 1.99657168, 1.3853152 , 1.12310601, 1.48196487],\n", + " [1.50645512, 1.45441129, 1.99766545, 1.01527978, 1.74056455],\n", + " [1.89252294, 1.85672339, 1.40971228, 1.88408338, 1.12032061]],\n", + "\n", + " [[1.83952757, 1.18767728, 1.20872664, 1.13426983, 1.49856332],\n", + " [1.67536136, 1.2492708 , 1.74735713, 1.3308693 , 1.79295865],\n", + " [1.09005245, 1.78621685, 1.48210981, 1.3134594 , 1.76338164]]])" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "d = c + a\n", + "d\n", + "#Now they have the same size" ] }, { @@ -191,11 +348,35 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code/answer here" + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.88223541 0.99657168 0.3853152 0.12310601 0.48196487]\n", + " [0.50645512 0.45441129 0.99766545 0.01527978 0.74056455]\n", + " [0.89252294 0.85672339 0.40971228 0.88408338 0.12032061]]\n", + "\n", + " [[0.83952757 0.18767728 0.20872664 0.13426983 0.49856332]\n", + " [0.67536136 0.2492708 0.74735713 0.3308693 0.79295865]\n", + " [0.09005245 0.78621685 0.48210981 0.3134594 0.76338164]]] \n", + "\n", + "[[[1.88223541 1.99657168 1.3853152 1.12310601 1.48196487]\n", + " [1.50645512 1.45441129 1.99766545 1.01527978 1.74056455]\n", + " [1.89252294 1.85672339 1.40971228 1.88408338 1.12032061]]\n", + "\n", + " [[1.83952757 1.18767728 1.20872664 1.13426983 1.49856332]\n", + " [1.67536136 1.2492708 1.74735713 1.3308693 1.79295865]\n", + " [1.09005245 1.78621685 1.48210981 1.3134594 1.76338164]]]\n" + ] + } + ], + "source": [ + "print(a,'\\n')\n", + "print(d)\n", + "#They have all the same size but the value is a + c" ] }, { @@ -207,11 +388,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 72, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[0.88223541, 0.99657168, 0.3853152 , 0.12310601, 0.48196487],\n", + " [0.50645512, 0.45441129, 0.99766545, 0.01527978, 0.74056455],\n", + " [0.89252294, 0.85672339, 0.40971228, 0.88408338, 0.12032061]],\n", + "\n", + " [[0.83952757, 0.18767728, 0.20872664, 0.13426983, 0.49856332],\n", + " [0.67536136, 0.2492708 , 0.74735713, 0.3308693 , 0.79295865],\n", + " [0.09005245, 0.78621685, 0.48210981, 0.3134594 , 0.76338164]]])" + ] + }, + "execution_count": 72, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "e = a*c\n", + "e" ] }, { @@ -223,11 +422,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code/answer here" + "execution_count": 73, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[ 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]]])" + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a == e\n", + "#The value in c == 1 so we multiply a by 1" ] }, { @@ -239,11 +456,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.9976654528667241 1.5282244665989573 1.015279777700545\n" + ] + } + ], + "source": [ + "d_max = np.max(d)\n", + "d_min = np.mean(d)\n", + "d_mean = np.min(d)\n", + "\n", + "print(d_max,d_min,d_mean)" ] }, { @@ -255,11 +484,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 74, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "f = np.empty((2,3,5))" ] }, { @@ -279,7 +508,14 @@ "metadata": {}, "outputs": [], "source": [ - "# your code here" + "\n", + "for values in d : \n", + " if value > d_mean :\n", + " value = 25\n", + " if value == d_mean :\n", + " value = 50\n", + " elif : \n", + " value == " ] }, { @@ -345,7 +581,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -359,7 +595,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.9.7" } }, "nbformat": 4,