詳解python中Numpy的屬性與創(chuàng)建矩陣
更新時間:2018年09月10日 08:34:30 投稿:laozhang
這篇文章給大家分享了關于python中Numpy的屬性與創(chuàng)建矩陣的相關知識點內容,有興趣的朋友們可以學習參考下。
ndarray.ndim:維度
ndarray.shape:形狀
ndarray.size:元素個數
ndarray.dtype:元素數據類型
ndarray.itemsize:字節(jié)大小
創(chuàng)建數組:
a = np.array([2,23,4]) # list 1d print(a) # [2 23 4]
指定數據類型:
a = np.array([2,23,4],dtype=np.int) print(a.dtype) # int 64
dtype可以指定的類型有int32,float,float32,后面不跟數字默認64
a = np.zeros((3,4)) # 數據全為0,3行4列 """
a = np.ones((3,4),dtype = np.int) # 數據為1,3行4列 a = np.empty((3,4)) # 數據為empty,3行4列
empty類型:初始內容隨機,取決于內存的狀態(tài)
a = np.arange(10,20,2) # 10-19 的數據,2步長 a = np.arange(12).reshape((3,4)) # 3行4列,0到11
reshape修改數據形狀,如3行4列
a = np.linspace(1,10,20) # 開始端1,結束端10,且分割成20個數據,生成線段
linspace可以確定數據的數量,而arrage不能確定數據的數量,同時,linspace也可以使用reshape定義結構。
相關文章
Python之urlencode和urldecode案例講解
這篇文章主要介紹了Python之urlencode和urldecode案例講解,本篇文章通過簡要的案例,講解了該項技術的了解與使用,以下就是詳細內容,需要的朋友可以參考下2021-08-08

