網(wǎng)站首頁 編程語言 正文
函數(shù)調(diào)用方法:
numpy.zeros(shape, dtype=float)
各個參數(shù)意義:
- shape:創(chuàng)建的新數(shù)組的形狀(維度)。
- dtype:創(chuàng)建新數(shù)組的數(shù)據(jù)類型。
- 返回值:給定維度的全零數(shù)組。
基礎用法:
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類型。
進階用法:
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.])]
"""
原文鏈接:https://blog.csdn.net/u011699626/article/details/122193581
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-08-19 ubuntu上設置Redis開機自啟
- 2022-06-24 Windows?Server?2012遠程默認端口3389的修改方法_win服務器
- 2022-05-10 spring管理事務@Transactional注解相關參數(shù)
- 2022-07-29 pytest?fixtures函數(shù)及測試函數(shù)的參數(shù)化解讀_python
- 2022-02-07 使用laravel框架開發(fā)接口時post請求報錯419,get請求正常
- 2022-07-16 不同存圖方式下的DFS和BFS實現(xiàn)
- 2022-11-07 python學習pymongo模塊的使用方法_python
- 2022-05-01 python?pandas庫讀取excel/csv中指定行或列數(shù)據(jù)_python
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支