Skip to content

Commit

Permalink
deploy: 6628318
Browse files Browse the repository at this point in the history
  • Loading branch information
javlintor committed Nov 23, 2023
1 parent 47b1d3e commit 85a65c7
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 25 deletions.
72 changes: 48 additions & 24 deletions _sources/notebooks/numpy/exercises.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {
"id": "kwQN5-E3Lx9K"
},
Expand Down Expand Up @@ -93,7 +93,7 @@
"id": "Rh2bkL8ICSmu",
"outputId": "23fcc50c-ee02-4ff3-c85b-b3d591e67a49"
},
"execution_count": 11,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
Expand All @@ -108,6 +108,30 @@
}
]
},
{
"cell_type": "code",
"source": [
"def conv(f, g):\n",
" n = f.size\n",
" m = g.size\n",
" convolucion = np.zeros(n + m - 1)\n",
" for k in range(n + m - 1):\n",
" for i in range(max(0, k - m + 1), min(k + 1, n)): # Esto es lo que faltaba\n",
" j = i + m - 1 - k\n",
" convolucion[k] += f[i] * g[j]\n",
"\n",
" return convolucion\n",
"\n",
"arr1 = np.arange(10)\n",
"arr2 = np.arange(5)\n",
"print(conv(arr1, arr2))"
],
"metadata": {
"id": "ngt7gMmQgZKz"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -162,7 +186,7 @@
"id": "miL1u4mZGjCz",
"outputId": "2f6e193d-ed04-4bca-d170-5c9b10f9a3ea"
},
"execution_count": 27,
"execution_count": null,
"outputs": [
{
"output_type": "stream",
Expand All @@ -187,7 +211,7 @@
"id": "7O5dVdTqIbPo",
"outputId": "a810dd7a-30d8-4016-e9b8-b13bb7fc0627"
},
"execution_count": 29,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
Expand Down Expand Up @@ -219,7 +243,7 @@
"metadata": {
"id": "5yafhFrtLiw_"
},
"execution_count": 38,
"execution_count": null,
"outputs": []
},
{
Expand All @@ -234,7 +258,7 @@
"id": "fNQmAk7iOgSp",
"outputId": "f93c4b35-d151-4180-f280-887cd788e87f"
},
"execution_count": 47,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
Expand All @@ -259,7 +283,7 @@
"metadata": {
"id": "W72NIj9uI8X9"
},
"execution_count": 41,
"execution_count": null,
"outputs": []
},
{
Expand All @@ -282,7 +306,7 @@
"id": "mNBwXnVNMG-K",
"outputId": "fb679204-86b5-4396-c51e-f5c738543e4a"
},
"execution_count": 74,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
Expand Down Expand Up @@ -369,7 +393,7 @@
"height": 453
}
},
"execution_count": 77,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
Expand Down Expand Up @@ -405,7 +429,7 @@
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 85,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
Expand All @@ -429,7 +453,7 @@
"metadata": {
"id": "eytKEUY3XWKF"
},
"execution_count": 98,
"execution_count": null,
"outputs": []
},
{
Expand All @@ -444,7 +468,7 @@
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 99,
"execution_count": null,
"outputs": [
{
"output_type": "stream",
Expand Down Expand Up @@ -473,7 +497,7 @@
"metadata": {
"id": "ck39YEbNU_CN"
},
"execution_count": 100,
"execution_count": null,
"outputs": []
},
{
Expand All @@ -488,7 +512,7 @@
"id": "eUV_MiyGMC9K",
"outputId": "9211ae0e-e2e9-4458-a494-d4e72a3acbdf"
},
"execution_count": 101,
"execution_count": null,
"outputs": [
{
"output_type": "stream",
Expand All @@ -513,7 +537,7 @@
"height": 453
}
},
"execution_count": 102,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
Expand Down Expand Up @@ -651,7 +675,7 @@
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 105,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
Expand Down Expand Up @@ -683,7 +707,7 @@
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 106,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
Expand Down Expand Up @@ -711,7 +735,7 @@
"metadata": {
"id": "sOBgn6HRadC9"
},
"execution_count": 136,
"execution_count": null,
"outputs": []
},
{
Expand All @@ -727,7 +751,7 @@
"metadata": {
"id": "vjD4ljn-cim1"
},
"execution_count": 138,
"execution_count": null,
"outputs": []
},
{
Expand All @@ -743,7 +767,7 @@
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 139,
"execution_count": null,
"outputs": [
{
"output_type": "stream",
Expand All @@ -767,7 +791,7 @@
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 140,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
Expand Down Expand Up @@ -808,7 +832,7 @@
"height": 448
}
},
"execution_count": 141,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
Expand Down Expand Up @@ -847,7 +871,7 @@
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 142,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
Expand All @@ -873,7 +897,7 @@
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 143,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
Expand Down
20 changes: 20 additions & 0 deletions notebooks/numpy/exercises.html
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,26 @@ <h2>Convoluciones de arrays<a class="headerlink" href="#convoluciones-de-arrays"
</div>
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">conv</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">g</span><span class="p">):</span>
<span class="n">n</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">size</span>
<span class="n">m</span> <span class="o">=</span> <span class="n">g</span><span class="o">.</span><span class="n">size</span>
<span class="n">convolucion</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n</span> <span class="o">+</span> <span class="n">m</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n</span> <span class="o">+</span> <span class="n">m</span> <span class="o">-</span> <span class="mi">1</span><span class="p">):</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">max</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">k</span> <span class="o">-</span> <span class="n">m</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span> <span class="nb">min</span><span class="p">(</span><span class="n">k</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="p">)):</span> <span class="c1"># Esto es lo que faltaba</span>
<span class="n">j</span> <span class="o">=</span> <span class="n">i</span> <span class="o">+</span> <span class="n">m</span> <span class="o">-</span> <span class="mi">1</span> <span class="o">-</span> <span class="n">k</span>
<span class="n">convolucion</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">+=</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="n">g</span><span class="p">[</span><span class="n">j</span><span class="p">]</span>

<span class="k">return</span> <span class="n">convolucion</span>

<span class="n">arr1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="n">arr2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">conv</span><span class="p">(</span><span class="n">arr1</span><span class="p">,</span> <span class="n">arr2</span><span class="p">))</span>
</pre></div>
</div>
</div>
</div>
</section>
<hr class="docutils" />
<section id="procesando-imagenes-con-numpy">
Expand Down
2 changes: 1 addition & 1 deletion searchindex.js

Large diffs are not rendered by default.

0 comments on commit 85a65c7

Please sign in to comment.