(numpy)基本運用-1
我為了要學機器學習,最近在加強numpy,panda和基礎數學的知識,
所以每天學習到筆記一下。
首先
import numpy as np
產生0-10的陣列
np.arange()
import numpy as np
data=np.arange(11)
print(data)
PS D:\python> & "C:/Program Files (x86)/python3.9.0/python.exe" d:/python/test2.py
[ 0 1 2 3 4 5 6 7 8 9 10]
產生3行4列的數組
data=np.arange(12).reshape(3, 4)
print(data)
PS D:\python> & "C:/Program Files (x86)/python3.9.0/python.exe" d:/python/test2.py
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
數組維度的個數
data.ndim
data=np.arange(12).reshape(3, 4)
print(data.ndim)
PS D:\python> & "C:/Program Files (x86)/python3.9.0/python.exe" d:/python/test2.py
2
數組元素的個數
data.size
print(data.size)
12數組元素的類型
print(data.dtype)
int32
沒有留言:
張貼留言