網站首頁 編程語言 正文
函數調用方法:
numpy.zeros(shape, dtype=float)
各個參數意義:
- shape:創建的新數組的形狀(維度)。
- dtype:創建新數組的數據類型。
- 返回值:給定維度的全零數組。
基礎用法:
import numpy as np
array = np.zeros([2, 3])
print(array)
print(array.dtype)
"""
result:
[[0. 0. 0.]
?[0. 0. 0.]]
float64
"""
可以看到我們成功創建了一個2行3列的全零二維數組。并且創建的數組中的數據類型是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
"""
可以看到,這里我們同樣成功創建了一個2行3列的全零二維數組。并且我們指定了其數據類型為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-04-09 Python中緩存lru_cache的基本介紹和講解_python
- 2022-07-28 Django實現視頻播放的具體示例_python
- 2023-12-15 Linux系統設置多個IP地址、默認路由、指定路由、永久刪除默認路由
- 2022-12-26 詳解C++11中的lambda匿名函數_C 語言
- 2022-08-04 python實現決策樹分類算法代碼示例_python
- 2022-04-12 input file詳細介紹、更改css樣式、獲取圖片地址、徹底清空上傳文件(建議收藏)
- 2022-07-08 Asp.Net?Core7?preview4限流中間件新特性詳解_實用技巧
- 2023-10-13 獲取element-ui的Collapse折疊后高度
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支