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

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

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

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

numpy.zeros(shape, dtype=float)

各個(gè)參數(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)建了一個(gè)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)建了一個(gè)2行3列的全零二維數(shù)組。并且我們指定了其數(shù)據(jù)類型為np.int32。

最高級(jí)的用法:

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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:

相關(guān)文章

最新評(píng)論

廊坊市| 吉首市| 建瓯市| 广饶县| 洛川县| 如皋市| 宁阳县| 诏安县| 吉木乃县| 左贡县| 汽车| 泽州县| 湖南省| 明水县| 齐齐哈尔市| 诸城市| 平南县| 连城县| 辽宁省| 宝鸡市| 江永县| 千阳县| 泸溪县| 察哈| 新巴尔虎右旗| 邯郸市| 揭东县| 大城县| 当雄县| 新密市| 曲松县| 嘉祥县| 罗平县| 固安县| 兴城市| 高密市| 中西区| 绥德县| 连平县| 周口市| 云梦县|