新聞中心
python中,ndarray是一個由同類元素組成的多維數(shù)組,可以針對數(shù)組運算提供大量的數(shù)學(xué)函數(shù)庫,功十分強(qiáng)大,要想使用ndarray,首先要創(chuàng)建ndarray,本文介紹創(chuàng)建ndarray的三種方法:1、使用array方法創(chuàng)建;2、使用zeros和ones函數(shù)直接得到全部為0和1矩陣;3、使用arange創(chuàng)建一個一維 ndarray 數(shù)組。

大東ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!
方法一:使用array方法創(chuàng)建
def test1(): # 使用array方法構(gòu)造 nd1 = np.array(list1) nd2 = np.array(list2) nd3 = np.array(tuple3) show_array_properties(nd1) show_array_properties(nd2) show_array_properties(nd3)
方法二:使用zeros和ones函數(shù)直接得到全部為0和1矩陣
zero_test = np.zeros((3,4), dtype=int) print(zero_test) ones_test = np.ones((4,4), dtype=int) print(ones_test)
方法三:使用arange創(chuàng)建一個一維 ndarray 數(shù)組
>>>c = np.arange(2,10,2,dtype=np.int32) >>>print(c) >[2 4 6 8] >>>d = np.arange(1,8,2,dtype=np.int32).reshape((2,2)) >>>print(d) >[[1 3] [5 7]]
以上就是小編整理總結(jié)的python中創(chuàng)建ndarray數(shù)組的三種方法,大家選擇其中一種方法使用即可,更多python學(xué)習(xí)推薦:python教程。
本文標(biāo)題:創(chuàng)新互聯(lián)Python教程:python中如何創(chuàng)建ndarray數(shù)組?
URL網(wǎng)址:http://m.fisionsoft.com.cn/article/dposjoo.html


咨詢
建站咨詢
