欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解python中Numpy的屬性與創(chuàng)建矩陣

 更新時(shí)間:2018年09月10日 08:34:30   投稿:laozhang  
這篇文章給大家分享了關(guān)于python中Numpy的屬性與創(chuàng)建矩陣的相關(guān)知識(shí)點(diǎn)內(nèi)容,有興趣的朋友們可以學(xué)習(xí)參考下。

ndarray.ndim:維度

ndarray.shape:形狀

ndarray.size:元素個(gè)數(shù)

ndarray.dtype:元素?cái)?shù)據(jù)類(lèi)型

ndarray.itemsize:字節(jié)大小

創(chuàng)建數(shù)組:

a = np.array([2,23,4]) 
# list 1d
print(a)
# [2 23 4]

指定數(shù)據(jù)類(lèi)型:

a = np.array([2,23,4],dtype=np.int)
print(a.dtype)
# int 64

dtype可以指定的類(lèi)型有int32,float,float32,后面不跟數(shù)字默認(rèn)64

a = np.zeros((3,4)) # 數(shù)據(jù)全為0,3行4列
"""

 

a = np.ones((3,4),dtype = np.int)  # 數(shù)據(jù)為1,3行4列
a = np.empty((3,4)) # 數(shù)據(jù)為empty,3行4列

empty類(lèi)型:初始內(nèi)容隨機(jī),取決于內(nèi)存的狀態(tài)

a = np.arange(10,20,2) # 10-19 的數(shù)據(jù),2步長(zhǎng)
a = np.arange(12).reshape((3,4))  # 3行4列,0到11

reshape修改數(shù)據(jù)形狀,如3行4列

a = np.linspace(1,10,20)  # 開(kāi)始端1,結(jié)束端10,且分割成20個(gè)數(shù)據(jù),生成線(xiàn)段

linspace可以確定數(shù)據(jù)的數(shù)量,而arrage不能確定數(shù)據(jù)的數(shù)量,同時(shí),linspace也可以使用reshape定義結(jié)構(gòu)。

相關(guān)文章

最新評(píng)論