標籤:預設 隨機數 隨機 items 自動識別 col sha 大小 and
import numpy as nplist = [[1,3,5,7],[2,4,6,8]]np_list = np.array(list) #將l列表資料轉化為數群組類型print(np_list)‘‘‘[[1 3 5 7] [2 4 6 8]]‘‘‘np_list1 = np.array(list,dtype=np.float) # 通過dtype定義數組的類型,預設的自動識別print(np_list1) #bool,int,int8,int32,int16,int64,int128,uint8等,float。float16/32/等‘‘‘[[ 1. 3. 5. 7.] [ 2. 4. 6. 8.]]‘‘‘#資料的屬性print(np_list.shape) # (2, 4) 兩行四列print(np_list.ndim) # 2 資料的維度print(np_list.dtype) # int32 數組的類型print(np_list.itemsize) # 4 每個資料的大小print(np_list.size) # 8 資料的個數# 一些數組 some arraysprint(np.ones((3,5)))‘‘‘[[ 1. 1. 1. 1. 1.] [ 1. 1. 1. 1. 1.] [ 1. 1. 1. 1. 1.]]‘‘‘ print(np.zeros((2,4)))‘‘‘[[ 0. 0. 0. 0.] [ 0. 0. 0. 0.]]‘‘‘ # 隨機數# randprint(np.random.rand(2,4)) #產生一個兩行四類的隨機數‘‘‘[[ 0.72024033 0.93403506 0.73121086 0.84075394] [ 0.98034306 0.6471637 0.77923702 0.44984363]]‘‘‘print(np.random.rand()) # 0.702153504735015 一個隨機數# randintprint(np.random.randint(1,10)) # 必須要填入數字範圍print(np.random.randint(1,10,3)) # 前面兩個數字是範圍,後面的一是輸出的隨機數個數# randn 標準動態產生的隨機數print(np.random.randn()) # 0.2021606168747088print(np.random.randn(2,4)) # 兩行四列的正態隨機數‘‘‘[[-0.43522053 0.288716 1.5751424 -0.89094638] [-1.12602864 1.27198812 -0.4784293 1.90768013]]‘‘‘# choice 隨機產生 制定數組內的 隨機數print(np.random.choice([10,20,30])) # 隨機產生一個隨機數print(np.random.choice([10,20,30],2)) # 隨機產生制定個隨機數# 數學函數的分布print(np.random.beta(1,10,100)) # beta函數的分布
python 資料分析