最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

np.zeros()函數(shù)的使用方法

 更新時間:2023年02月28日 10:16:08   作者:勤奮的大熊貓  
本文主要介紹了np.zeros()函數(shù)的使用方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

函數(shù)調(diào)用方法:

numpy.zeros(shape, dtype=float)

各個參數(shù)意義:

  • shape:創(chuàng)建的新數(shù)組的形狀(維度)。
  • dtype:創(chuàng)建新數(shù)組的數(shù)據(jù)類型。
  • 返回值:給定維度的全零數(shù)組。

基礎(chǔ)用法:

import numpy as np

array = np.zeros([2, 3])
print(array)
print(array.dtype)
"""
result:
[[0. 0. 0.]
?[0. 0. 0.]]
float64
"""

可以看到我們成功創(chuàng)建了一個2行3列的全零二維數(shù)組。并且創(chuàng)建的數(shù)組中的數(shù)據(jù)類型是np.float64類型。

進(jìn)階用法:

import numpy as np

array = np.zeros([2, 3], dtype=np.int32)
print(array)
print(array.dtype)
"""
result:
[[0 0 0]
?[0 0 0]]
int32
"""

可以看到,這里我們同樣成功創(chuàng)建了一個2行3列的全零二維數(shù)組。并且我們指定了其數(shù)據(jù)類型為np.int32。

最高級的用法:

import numpy as np

# Create rain data
n_drops = 10

rain_drops = np.zeros(n_drops, dtype=[('position', float, (2,)),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ('size', float),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ('growth', float),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ('color', float, (4,))])

# Initialize the raindrops in random positions and with
# random growth rates.
rain_drops['position'] = np.random.uniform(0, 1, (n_drops, 2))
rain_drops['growth'] = np.random.uniform(50, 200, n_drops)

print(rain_drops)
"""
result:
[([0.70284885, 0.03590322], 0., 176.4511602 , [0., 0., 0., 0.])
?([0.60838294, 0.49185854], 0., ?60.51037667, [0., 0., 0., 0.])
?([0.86525398, 0.65607663], 0., 168.00795695, [0., 0., 0., 0.])
?([0.25812877, 0.14484747], 0., ?80.17753717, [0., 0., 0., 0.])
?([0.66021716, 0.90449213], 0., 121.94125106, [0., 0., 0., 0.])
?([0.88306332, 0.51074725], 0., ?92.4377108 , [0., 0., 0., 0.])
?([0.68916433, 0.89543162], 0., ?90.77596431, [0., 0., 0., 0.])
?([0.7105655 , 0.68628326], 0., 144.88783652, [0., 0., 0., 0.])
?([0.6894679 , 0.90203559], 0., 167.40736266, [0., 0., 0., 0.])
?([0.92558218, 0.34232054], 0., ?93.48654986, [0., 0., 0., 0.])]
"""

到此這篇關(guān)于np.zeros()函數(shù)的使用方法的文章就介紹到這了,更多相關(guān)np.zeros()使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:

相關(guān)文章

最新評論

鹤峰县| 馆陶县| 宁武县| 任丘市| 石景山区| 辽阳市| 黄浦区| 长春市| 娄底市| 化德县| 井研县| 刚察县| 鸡西市| 丰台区| 泸州市| 天峻县| 东宁县| 泌阳县| 麟游县| 军事| 宿州市| 达孜县| 阿克陶县| 平顶山市| 台湾省| 东辽县| 夏邑县| 开阳县| 西贡区| 壤塘县| 儋州市| 朝阳区| 韶关市| 策勒县| 岳阳县| 贵阳市| 剑河县| 资兴市| 宁强县| 昌平区| 昆明市|