<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: slackman</title>
    <description>The latest articles on DEV Community by slackman (@slackman).</description>
    <link>https://dev.to/slackman</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3738555%2F73953242-b88d-4dbd-8138-2448a353d9fd.jpg</url>
      <title>DEV Community: slackman</title>
      <link>https://dev.to/slackman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/slackman"/>
    <language>en</language>
    <item>
      <title>Python sigmoid()</title>
      <dc:creator>slackman</dc:creator>
      <pubDate>Sat, 28 Feb 2026 05:19:38 +0000</pubDate>
      <link>https://dev.to/slackman/python-sigmoid-kgh</link>
      <guid>https://dev.to/slackman/python-sigmoid-kgh</guid>
      <description>&lt;p&gt;$$&lt;br&gt;
f(x) = \frac{1}{ (1 + e^{-x}) } &lt;br&gt;
$$&lt;/p&gt;

&lt;p&gt;$$&lt;br&gt;
f'(x) = f * (1-f)&lt;br&gt;
$$&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Futz2pczoqu2ocsnzhpky.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Futz2pczoqu2ocsnzhpky.png" alt=" " width="800" height="235"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;pip install numpy matplotlib sympy&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import numpy as np
import matplotlib.pyplot as plt
import sympy as sp

x = sp.Symbol('x')
f1 = 1 / (1 + sp.exp(-1*x))
df1 = sp.diff(f1, x)

f1 = sp.lambdify(x, f1, 'numpy')
df1 = sp.lambdify(x, df1, 'numpy')

x = np.linspace(-10, 10, 400)
y = f1(x)
y_df = df1(x)

plt.figure(figsize=(8, 5))
# 1行2列
plt1 = plt.subplot(1,2,1)
plt2 = plt.subplot(1,2,2)
plt1.plot(x, y, label='f(x)', color='blue')
plt2.plot(x, y_df, label='df(x)', color='red')

plt1.grid()
plt2.grid()
plt1.legend()
plt2.legend()
plt.show()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsx3srtpuvhwpu8hj2b4h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsx3srtpuvhwpu8hj2b4h.png" alt=" " width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;sigmoid 函数可以将任意的输入映射到 (0, 1) 之间&lt;br&gt;
输入值在 [-6, 6] 之间输出值才会有明显差异，&lt;br&gt;
输入值在 [-3, 3] 之间才会有比较好的效果。&lt;/p&gt;

&lt;p&gt;The sigmoid function maps any input to a value within the interval (0, 1).&lt;br&gt;
The output varies significantly only when the input is within the range [-6, 6],&lt;br&gt;
and performs well especially when the input is within [-3, 3].&lt;/p&gt;

&lt;p&gt;sigmoid 导数范围是 (0, 0.25)&lt;br&gt;
当输入 &amp;lt;-6 或者 &amp;gt;6 时，sigmoid 激活函数图像的导数接近为 0，&lt;br&gt;
此时网络参数将更新极其缓慢，或者无法更新。&lt;/p&gt;

&lt;p&gt;The derivative of the sigmoid function lies in the range (0, 0.25).&lt;br&gt;
When the input is less than -6 or greater than 6, the derivative of the sigmoid activation function approaches zero,&lt;br&gt;
causing the network parameters to update very slowly or even stall completely.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>machinelearning</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Python f(x) &amp; grad</title>
      <dc:creator>slackman</dc:creator>
      <pubDate>Sat, 28 Feb 2026 02:14:54 +0000</pubDate>
      <link>https://dev.to/slackman/python-fx-grad-158m</link>
      <guid>https://dev.to/slackman/python-fx-grad-158m</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = [10.0]
for _ in range(5):
    s.append(s[-1] * 0.98)

s = [10.0, 9.8, 9.6]

loss = lambda x: (x**2) + 20
grad = lambda x: x*2

w = 9.8
print(loss(w), grad(w))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;极值点, 导数为0,  grad递减&lt;/p&gt;

&lt;p&gt;At the extremum point, the derivative is zero, and the gradient is decreasing&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import matplotlib.pyplot as plt
import numpy as np

w = [10.0]
for _ in range(100):
    w.append(w[-1] * 0.98)

x = np.array(w)
y = np.pow(x,2) + 20
y_grad = x * 2


plt.figure(figsize=(10, 6))
plt.xlim(10,0)
plt.scatter(x, y, label = 'f(x)', color='blue')
plt.scatter(x, y_grad, label = "grad(x)", color='red')

plt.grid()
plt.legend()
plt.tight_layout()
plt.show()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0yvqyq9w2i6ohfbz51nr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0yvqyq9w2i6ohfbz51nr.png" alt=" " width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>machinelearning</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Python quick_sort</title>
      <dc:creator>slackman</dc:creator>
      <pubDate>Mon, 09 Feb 2026 08:33:00 +0000</pubDate>
      <link>https://dev.to/slackman/python-quicksort-1e65</link>
      <guid>https://dev.to/slackman/python-quicksort-1e65</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def quick_sort(arr):
  if len(arr) &amp;lt;=1:
     return arr
  pivot = arr[0]
  left = []
  right = []
  for num in arr[1:]:
     if num &amp;lt;= pivot:
        left.append(num)
     else:
        right.append(num)
   return quick_sort(left) + [pivot] + quick_sort(right)

source = [1,5,3]
target = [1,3,5]
## list.eq 包含相同的元素，并且顺序相同
print(quick_sort(source) == target)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  AO - 01
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pivot_index = random.randint(0, len(arr))
pivot = arr[pivot_index]

for i,num in enumerate(arr):
   if pivot_index == i:
     continue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  AO - 02
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def insert_sort(arr):
   for i in range(1,len(arr)):
       key = arr[i]
       j = i-1
       while j&amp;gt;=0 and key &amp;lt; arr[j]:
          arr[j+1] = arr[j]
          j-=1
       arr[j+1] = key
    return arr

def quick_sort(arr):
  if len(arr) &amp;lt;=1:
     return arr
  if len(arr) &amp;lt; 10:
     return insert_sort(arr)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>algorithms</category>
      <category>computerscience</category>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>Python json&amp;csv file</title>
      <dc:creator>slackman</dc:creator>
      <pubDate>Tue, 03 Feb 2026 08:03:17 +0000</pubDate>
      <link>https://dev.to/slackman/python-jsoncsv-217n</link>
      <guid>https://dev.to/slackman/python-jsoncsv-217n</guid>
      <description>&lt;p&gt;import json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data1 = {
    'no' : 1,
    'name' : 'Nobel',
}
json_str = json.dumps(data1)
data2 = json.loads(json_str)

with open('data.json', 'w', encoding='utf-8') as f:
    json.dump(data1, f)
with open('data.json', 'r', encoding='utf-8') as f:
    data = json.load(f)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;import csv&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rows = [{'gid': '111', 'title': '222'}]
fieldnames = ['gid', 'title']
with open('example.csv', 'w', newline='', encoding='utf-8') as file:
    writer = csv.DictWriter(file, fieldnames=fieldnames)
    writer.writeheader()
    writer.writerow({'gid': '000', 'title': '111'})
    writer.writerows(rows)

# with Header
with open('example.csv', mode='r', encoding='utf-8') as f:
    reader = csv.DictReader(f)
    headers = reader.fieldnames
    for row in reader:
        print(row)

# no Header
with open('example.csv', mode='r', encoding='utf-8') as f:
    my_fields = ['gid', 'title']
    reader = csv.DictReader(f, fieldnames=my_fields)
    for row in reader:
        print(row)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Python json_md5</title>
      <dc:creator>slackman</dc:creator>
      <pubDate>Thu, 29 Jan 2026 01:58:16 +0000</pubDate>
      <link>https://dev.to/slackman/python-jsonmd5-4859</link>
      <guid>https://dev.to/slackman/python-jsonmd5-4859</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import hashlib
import json

names = ["Tom", "John", "Tom"]

def json_md5(name):
    json_str = json.dumps({"name": name})
    hash1 = hashlib.md5()
    hash1.update(json_str.encode('utf-8'))
    return hash1.hexdigest()

names_md5key = [json_md5(name) for name in names]
assert len(names_md5key[0]) == 32
assert names_md5key[0] == names_md5key[2]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Python math.gcd</title>
      <dc:creator>slackman</dc:creator>
      <pubDate>Thu, 29 Jan 2026 01:30:07 +0000</pubDate>
      <link>https://dev.to/slackman/python-mathgcd-2eo</link>
      <guid>https://dev.to/slackman/python-mathgcd-2eo</guid>
      <description>&lt;p&gt;(10,2) =&amp;gt; 2&lt;br&gt;
(3, 5) =&amp;gt; 1&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def gcd(a,b):
    if a &amp;lt; b:
        a,b = b,a
    while b:
        a,b = b,a%b
    return a

import math

assert gcd(13, 2436) == 1
assert gcd(10, 2) == 2
assert math.gcd(13, 2436) == 1
assert math.gcd(10, 2) == 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>algorithms</category>
      <category>beginners</category>
      <category>code</category>
      <category>python</category>
    </item>
  </channel>
</rss>
