原创 numpy中級學習

""" numpy下的常見方法: all,any,argmax, argmin,argpartition,argsort,choose, clip, compress,copy,cumprod, cumsum,di

原创 異步【ThreadPoolExecutor】和【ProcessPoolExecutor】運算比較

from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor, as_completed import time number_list = [1,

原创 生成器還可以疊加來組成生成器管道

# Fibonacci數生成器 def fib(): a, b = 0, 1 while True: a, b = b, a + b yield a # 偶數生成器 def ev

原创 運用staticmethod裝飾器的簡單方式

from math import sqrt class Triangle(object): def __init__(self, a, b, c): self._a = a self.

原创 Python threading Lock同步線程

原因:如果多個線程共同對某個數據修改,則可能出現不可預料的結果,爲了保證數據的正確性,需要對多個線程進行同步。 # coding=utf-8 import logging import threading import time

原创 Python threading Event類實現事件的對象(對子線程的事件管理)

原因:主線程要控制其他線程的執行 注意:event.wait(timeout) 要設置超時時間【看註釋哦】,可以理解一下守護線程。 # coding=utf-8 import logging import threading im

原创 python threading Condition 條件變量

原因:在生產者跟消費者模式中,消費者判斷有沒有產品,這就形成一個判斷。。。 import logging import threading import time from random import randint from t

原创 Python threading Barrier柵欄(保存等待的線程對象,達到柵欄數量後,釋放柵欄)

原因:遊戲項目中,必須三個人才能進入下一關遊戲,不然就算超時等待或退出遊戲 # coding=utf-8 import logging import threading logging.basicConfig( leve

原创 Python Threading Semaphore信號量(子線程的數量)

原因:主要用在保護有限的資源。 假設當前數據庫支持最大連接數爲3,將信號量初始值設爲3,那麼同時最大可以有三個線程連接數據庫,其他線程若再想連接數據庫,則只有等待,直到某一個線程釋放數據庫連接。 注意:輸出結果是每兩秒打印的,跟數

原创 pandas基礎學習

import numpy as np import pandas as pd print(pd.__version__)#檢查版本 print(pd.show_versions(as_json=True))#檢查版本 # 如何

原创 多圖合併顯示

import numpy as np import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec from matplotlib import an

原创 三種方式的階乘

import logging logging.basicConfig( # 用日誌打印輸出信息 level = logging.INFO, format = "%(asctime)s [*] %(message

原创 優雅地處理不同響應碼的異步請求

urls.txt 文件 https://regex101.com/ https://docs.python.org/3/this-url-will-404.html https://www.nytimes.com/guides/

原创 python 多線程與隊列

隊列-單線程 import threading import queue#不是線程模塊的隊列 import time class worker(threading.Thread): def __init__(self,

原创 拉勾網java分析

import pandas as pd import matplotlib.pyplot as plt plt.rcParams['font.sans-serif'] = ['SimHei'] # 用來正常顯示中文標籤 plt.