Numpy 的 ones(~)
方法返回一個用 1 填充的 Numpy 數組。
參數
1.shape
| int
或 tuple
或 int
所得數組的所需形狀。如果提供了int,則返回一維數組。
2. dtype
| string
或 type
| optional
返回的單位矩陣所需的數據類型。默認情況下,dtype=Float64
。
返回值
一個充滿 1 的 Numpy 數組。
例子
創建一維數組
創建一個大小為 3 並填充零的一維數組:
np.ones(3)
array([1., 1., 1.])
要創建類型為 int64
的一維數組:
np.ones(3, dtype="int64")
array([1, 1, 1])
創建二維數組
創建 2 x 3 二維數組:
np.ones((2,3))
array([[1., 1., 1.],
[1., 1., 1.]])
相關用法
- Python numpy matrix ones()用法及代碼示例
- Python os.path.normcase()用法及代碼示例
- Python os.read()用法及代碼示例
- Python os.DirEntry.inode()用法及代碼示例
- Python os.closerange()用法及代碼示例
- Python os.set_blocking()用法及代碼示例
- Python os.pathconf()用法及代碼示例
- Python os.chflags()用法及代碼示例
- Python open()用法及代碼示例
- Python operator.truth()用法及代碼示例
- Python os.WCOREDUMP()用法及代碼示例
- Python os.fork()用法及代碼示例
- Python os.ctermid()用法及代碼示例
- Python os.mkfifo()用法及代碼示例
- Python os.tcsetpgrp()用法及代碼示例
- Python os.path.commonpath()用法及代碼示例
- Python os.path.splitdrive用法及代碼示例
- Python os.mkdir()用法及代碼示例
- Python os.close()用法及代碼示例
- Python os.chroot()用法及代碼示例
- Python os.ttyname()用法及代碼示例
- Python os.path.splitext用法及代碼示例
- Python os.setregid()用法及代碼示例
- Python os.abort()用法及代碼示例
- Python object()用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 NumPy | ones method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。