numpy中的ndim、shape、dtype、astype
生活随笔
收集整理的這篇文章主要介紹了
numpy中的ndim、shape、dtype、astype
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.ndim
ndim返回的是數組的維度,返回的只有一個數,該數即表示數組的維度。
print(np.random.rand(2).ndim) #1 print(np.random.rand(2,1).ndim) # 22.shape
shape:表示各位維度大小的元組。返回的是一個元組。
print(np.random.rand(2).shape) # (2,) 一維數組元組內只返回一個數 print(np.random.rand(2,1).shape) # (2, 1) 二維數組元組內返回2個數 print(np.random.rand(2,2,1).shape) # (2, 2, 1) 三維數組元組內返回3個數3.dtype
一個用于說明數組數據類型的對象。返回的是該數組的數據類型。
print(np.random.rand(2).dtype) # float644.astype
astype:轉換數組的數據類型。
m = np.random.rand(2) print(m.astype(np.float32).dtype) # 將float64數據類型轉為float32類型總結
以上是生活随笔為你收集整理的numpy中的ndim、shape、dtype、astype的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: numpy.random.rand、nu
- 下一篇: np.zeros(),np.empty(