1. 程式人生 > >【python】零碎總結_轉

【python】零碎總結_轉

1 產生資料

  隨機產生(0,1)中的資料: np.random.random(2)      # array([ 0.66516976,  0.44746339])

  隨機產生一個區間內的指定個數 :np.random.randint(-10,10,12).reshape(3,4)   #array([[-9,  6, -1,  9],[ 7, -1, -4,  3],[ 7,  5,  3,  6]])

  range:range(start,end,step):

np.arange(2) #array([0, 1])

 np.arange(2,10,2)  #array([2, 4, 6, 8])

 http://www.jb51.net/article/50066.htm

2 python * ** 的用法

 * 用來傳遞任意個無名字引數,這些引數會一個Tuple的形式訪問。

   **用來處理傳遞任意個有名字的引數,這些引數用dict來訪問。*

3

zip函式接受任意多個(包括0個和1個)序列作為引數,返回一個tuple列表。

x = [1, 2, 3]

y = [4, 5, 6]

z = [7, 8, 9]

xyz = zip(x, y, z)

print xyz

[(1, 4, 7), (2, 5, 8), (3, 6, 9)]