原创 Bare asterisk in function arguments
Suppose you have function: def sum(a,key=5): return a + key You can call this function in 2 ways: sum(1,2) or sum
原创 Difference between np.random.seed() and np.random.RandomState()
numpy.random.seed(0) resets the state of the existing global RandomState instance that underlies the functions in the n
原创 裝飾器wraps
def a_new_decorator(a_func): def wrapTheFunction(): print("I am doing some boring work before executing
原创 Python秋招面經
算法編程題 1 冒泡排序 思想:冒泡排序從小到大排序:一開始交換的區間爲0~N-1,將第1個數和第2個數進行比較,前面大於後面,交換兩個數,否則不交換。再比較第2個數和第三個數,前面大於後面,交換兩個數否則不交換。依次進行,最大的數會放在
原创 劍指Offer-1-二維數組中的查找
題目:二維數組中,每行從左到右遞增,每列從上到下遞增,給出一個數,判斷它是否在數組中 思路:從左下角或者右上角開始比較 # -*- coding:utf-8 -*- class Solution: # array 二維列表
原创 What is the meaning of a forward slash “/” in a Python method signature?
As explained here, the '/' as a parameter marks the end of parameters that are positional only (see here), i.e. paramet
原创 Python中的抽象方法@abstractmethod
抽象方法是父類的一個方法, 父類沒有實現這個方法, 父類是不可以實例化的. 子類繼承父類, 子類必須實現父類定義的抽象方法, 子類纔可以被實例化. Python中的abc提供了@abstractmethod裝飾器實現抽象方法的定義。 抽象
原创 hexo使用markdown圖片無法顯示問題
hexo默認無法自動處理文章插入本地圖片,需要通過擴展插件支持。 圖片路徑問題 配置_config.yml裏面的post_asset_folder:false這個選項設置爲true。 安裝hexo-asset-image,運行hexo n
原创 Filtering data with Pandas .query() method
Syntax: DataFrame.query(expr, inplace=False, **kwargs) Parameters:expr: Expression in string form to filter data.inpl
原创 Is there a reason why people use super(class, self).__init__() instead of super().__init__()?
I suppose people use it to make the code compatible with Python2.x. Otherwise all Python2 users would have to add the c
原创 mysql字符串函數:Locate()
語法 一: LOCATE(substr,str) 返回字符串substr中第一次出現子字符串的位置 str。 語法二: LOCATE(substr,str,pos) 返回字符串substr中第一個出現子 字符串的 str位置,從位置開
原创 LeetCode-276. 柵欄塗色
有 k 種顏色的塗料和一個包含 n 個柵欄柱的柵欄,每個柵欄柱可以用其中一種顏色進行上色。 你需要給所有柵欄柱上色,並且保證其中相鄰的柵欄柱 最多連續兩個 顏色相同。然後,返回所有有效塗色的方案數。 注意: n 和 k 均爲非負的整數。
原创 在Jupyter Notebook裏設置斷點
安裝ipdb pip install ipdb 用法 import ipdb def fun(a): ipdb.set_trace() # 在這裏開始調試 return do_some_thing_about(b)
原创 ubuntu 安裝 nvidia 驅動
第一步:卸載原驅動 $sudo apt-get remove nvidia-* $sudo apt-get autoremove 第二步:輸入CTRL+ALT+F1進入文本模式 第三步:臨時關閉顯示服務 $sudo service l
原创 What is the difference between size and count in pandas?
That is the difference between groupby("x").count and groupby("x").size in pandas ? Answer: size includes NaN values,